I think you could use X ;: bits where bits is a sequence of '0' and '1' characters, if you used ;: opcode 6 (stop) on reaching the payload part of the packet.
An example implementation would then interpret the first word of the result as the puzzle opcode. If the opcode was 4, it would interpret the remainder as a number. Otherwise, it would interpret the remainder as a length and after skipping over a number of characters represented by that ;: result, it would extract that length from the stream and call itself recursively on that part and on the part which followed that part. But, yes... the puzzles seem to have a strong influence from the lisp community (specifically the compiler implementation part of that community). Thanks, -- Raul On Wed, Jan 12, 2022 at 9:02 AM Stefan Baumann <[email protected]> wrote: > > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
