> Using ;: is at least 10 times quicker than using cut (;.) - because
On what evidence is this statement based?
Does not foo1=:((([EMAIL PROTECTED]@(<;._1)@(':'&,)));._1)@('+'&,) immediately
give what
you want?
foo1 '0:A++123.9:A:M:-+87:B+123:A:S'
+-++-+-+-+
|A||A|B|A|
+-++-+-+-+
(1{"1 foo)'0:A++123.9:A:M:-+87:B+123:A:S'
+-++-+-+-+
|A||A|B|A|
+-++-+-+-+
foo1 is hardly more efficient:
DATA=:([EMAIL PROTECTED]){ ''''-.~1 { 8 32 $ a.
ts'foo1 DATA'
0.0088542596 286592
ts'(1{"1 foo) DATA'
0.011645331 1018176
(foo1 -: 1{"1 foo) DATA
1
R.E. Boss
-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens david alis
Verzonden: maandag 22 januari 2007 8:45
Aan: Programming forum
Onderwerp: [Jprogramming] Re: Programming sequential machine/finite state
machine
Applying this sm to your last two examples
+:123+34+
+123+:34+
doesnt provide the result needed..
+:123+34+ should produce two elements - the first being 123 while the
second should be empty. Instead the sm puts '4' into the second
element.
+123+:34+ should also have two elements, the first being empty - but
this time the sm puts '3' into the first element.
How do I determine whether a particular problem can be solved using a fsm?
In my actual application I use the verb 'foo' on strings such as
'data' (the application specifies there is a maximum of 4 elements
within each part).
foo =: ((((4&{.)@(<;._1)@(':'&,)));._1)@('+'&,)
data=: '0:A++123.9:A:M:-+87:B+123:A:S'
foo data
+-----+-+-+-+
|0 |A| | |
+-----+-+-+-+
| | | | |
+-----+-+-+-+
|123.9|A|M|-|
+-----+-+-+-+
|87 |B| | |
+-----+-+-+-+
|123 |A|S| |
+-----+-+-+-+
from which I can extract the pieces I need.
Using ;: is at least 10 times quicker than using cut (;.) - because
of the need to apply ;. explicitly within each substring. But because
I rely on ;: to always produce the correct result.
Thanks for your efforts.
Regards
David
Raul Miller wrote: <Mon Jan 22 11:56:55 HKT 2007>
....
NB. + : NB. each entry is nextState.outputCode
sc=:0 10#:10*".;._2(0 :0)
1.1 1.1 1.1 NB. 0 initial state
1.2 2.1 1.1 NB. 1 got '+', waiting for first ':'
1.2 3.3 4.1 NB. 2 got '+:', handle next char
1.1 3.0 3.0 NB. 3 got '+::', waiting for next '+'
1.2 3.3 4.0 NB. 4 got '+:x' waiting for + or :
)
pp=: '+:'i.a.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm