I didn't get a grip on this problem at the beginning and skipped it.
But inspired by Raul's solution it appeared that the problem input looks
like an encoded LISP expression.
So I tried to parse the data into a LISP-like J expression and was
wondering if I could then apply ". on it.
The parsing verb ps takes the first position of the packet as y and returns
r, the position right after the packet.
Global nouns V and E store the version numbers and the mentioned J
expression, resp..
J session follows, I hope it's comprehensible - I wanted to keep it very
compact and therefore didn't write any comments.
rd=: [: ,/@#: '0123456789ABCDEF'&i.
$d=: rd 'C0015000016115A2E0802F182340'
112
o=: <;._1 ' +/ */ <./ >./ 0: >/ </ =/'
ps=: 3 : 0
y=. y+6 [ E=: E,',' [ V=: V,{. 'v t'=. #.{&d y+i.2 3
if. t=4 do. z=. (-~ +&5^:({&d)^:_) y
E=: E, ": #.{&d ,|: (>:y+i.4) +/ i.@>:&.(%&5) z
r=. y+z+5
else. E=: E,'(', t{::o
if. {&d <: y=. >:y do. n=. #.{&d y+i.11
r=. ps^:n y+11
else. l=. y+15 + #.{&d y+i.15
r=. ps^:(<&l)^:_ y+15
end. E=: E,')'
end. r
)
{{ ps y [ E=: V=: '' }} 0
106
+/ V NB. (*)
23
". E NB. (**)
46
E
,(+/,(+/,10,11),(+/,12,13))
Although ps is defined recursively, it actually just parses from left to
right.
Therefore I'm still wondering if this could be a use case for sequential
machine ;: which I was actually thinking of at the beginning.
Thanks. Stefan.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm