Here's my day 8 - again, abusing my byte code interpreter -- which
seems like a good fit because it can peek ahead in the stream

part 1 approach: generate COUNT instruction for each character. Skip
over characters if they are escaped

Only around 10 lines of new code written to support it - hooray for
reuse of fixed tacit code

https://gist.github.com/joebo/ac24022f7c20dbf745d4

Much shorter this time:

answer1=: (([: +/ (# every)) - (+/ @: ((getVAL @ run @ compile 0&{)
every (,:@}.@}:) each))) f.
smoutput ;"1 ,. _50<\ lr 'answer1'

         ([: +/ #&>) - +/@:(((2 {:: ])@((>:@:(1 {:: ]) (<@:
[ 1} ]) ])@:(((1 {:: ]) { 0 {:: ]) (>:@:(1 {:: ])
(<@:[ 1} ]) ])^:(0:`(1:`1:`3:@.(92 34 120 i. 1&{@(
(1 + 1 {:: ]) { 0 {:: ])))@.(92 = 1&{@((0 + 1 {::
]) { 0 {:: ])))@:(>:@(2 {:: ])&] (<@:[ 2} ]) ])`((
1:`1:`0:@.(92 34 i. 1&{@((0 + 1 {:: ]) { 0 {:: ]))
 + >:@((2 {:: ])&])) (<@:[ 2} ]) ])`(_&(<@:[ 1} ])
)@.(0 {:: [) ])^:(1 = (1 {:: ]) < <:@:#@:[)^:_ (]
;&(0;0;'';'')))@(2 0 ,~ a. (0 ,"0 ])@i. ]) 0&{)&>
,:@}.@}:&.>)

answer1 lines
   1350


answer2 is included in the gist as well

On Tue, Dec 8, 2015 at 10:23 AM, David Lambert <b49p23t...@gmail.com> wrote:
> Part 1, a chance to exercise the FSM.  The states here are sufficient for
> character count.  Raul's annotated state table style is worth reiterating,
> hence this post.  Fixed width font aligns the columns.
>
> mp=: +/ .*
>
> S=: +. ". }. [;._2 noun define
> bore hex  \    "    x    LF
> 0j6  0j6  0j6  6j0  0j6  0j0  NB. 0 between strings j=_1
> 2j1  2j1  3j0  1j3  2j1  0j0  NB. 1 terminating "
> 2j0  2j0  3j3  1j3  2j0  0j6  NB. 2 amid string
> 0j6  0j6  2j1  2j1  4j0  0j6  NB. 3 allow \"x after leading \
> 0j6  5j0  2j1  2j1  5j0  0j6  NB. 4 first hex digit
> 0j6  2j1  0j6  0j6  0j6  0j6  NB. 5 second hex digit
> 2j1  2j1  3j0  1j0  2j1  0j6  NB. 6 first char of string
> )
>
> M=: a.(>:@i.@#@] mp (e.>)"1 0)'0123456789abcdef';;/'\"x',LF
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to