I have completed a first attempt at implementing Jimmy's
ideas of parsing the symbolic list of directional moves.
With Raul's help in making the tacit agenda code work, I
put together the following J calculations. The main verb
below is `all` and applying it iteratively to the data
list, I put the result in the noun `test` for further
analysis.

As you can see test contains 939 directions, so further
processing is required. Please see below for further
comments.


   #;:test =: ((all :: ])&. ;:)^: _ toupper data rplc ',';' '
939           NB. if data includes an ending LF, use }: also
   ~.;: test
┌──┬─┬──┐
│NE│N│SE│
└──┴─┴──┘
   15{.;: test      NB. just to explore
┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
│NE│NE│NE│NE│NE│NE│NE│NE│NE│NE│NE│NE│NE│NE│NE│
└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘
   _15{.;: test     NB. more exploring
┌──┬──┬─┬──┬──┬──┬──┬──┬──┬─┬─┬─┬─┬──┬─┐
│NE│NE│N│SE│SE│NE│NE│SE│SE│N│N│N│N│NE│N│
└──┴──┴─┴──┴──┴──┴──┴──┴──┴─┴─┴─┴─┴──┴─┘
   #/.~ ;:test
563 243 133          NB. NEs,Ns,SEs ; see nub next
   ~.;: test
┌──┬─┬──┐
│NE│N│SE│
└──┴─┴──┘
   +/563 133 110      NB. used because 243>133 => 133 more NEs
806
   +/\563 133 110     NB. looking again at cumulatives
563 696 806

NB.  BINGO, that 696 was the correct answer for my data
NB.  because 563+133 NEs  "erase" the remaining 110 Ns

So, this approach is enlightening, but I am not
clear on how to generalize on the post-processing
analysis, or how to change the processing to eliminate
the need for the post-processing analysis.

I'll attempt to supply the code needed below.
The data may be different for each person on AoC, I'm not sure.

swi =: [:(<./,]i.<./)(;:'NE SE N') i.~ ]
sw0 =: a:-.~(a:"_)`(0,{.@[)`]}
sw1 =: a:-.~(('S';a:)"_)`(0,{.@[)`]}
sw2 =: a:-.~(('NW';a:)"_)`(0,{.@[)`]}
swa =: ({.@] sw0 [)`({.@] sw1 [)`({.@] sw2 [)@.({:@] ) swi

nwi =: [:(<./,]i.<./)(;:'SE NE S') i.~ ]
nw0 =: a:-.~(a:"_)`(0,{.@[)`]}
nw1 =: a:-.~(('N';a:)"_)`(0,{.@[)`]}
nw2 =: a:-.~(('SW';a:)"_)`(0,{.@[)`]}
nwa =: ({.@] nw0 [)`({.@] nw1 [)`({.@] nw2 [)@.({:@] ) nwi

sei =: [:(<./,]i.<./)(;:'NW SW N') i.~ ]
se0 =: a:-.~(a:"_)`(0,{.@[)`]}
se1 =: a:-.~(('S';a:)"_)`(0,{.@[)`]}
se2 =: a:-.~(('NE';a:)"_)`(0,{.@[)`]}
sea =: ({.@] se0 [)`({.@] se1 [)`({.@] se2 [)@.({:@] ) sei

nei =: [:(<./,]i.<./)(;:'SW NW S') i.~ ]
ne0 =: a:-.~(a:"_)`(0,{.@[)`]}
ne1 =: a:-.~(('N';a:)"_)`(0,{.@[)`]}
ne2 =: a:-.~(('SE';a:)"_)`(0,{.@[)`]}
nea =: ({.@] ne0 [)`({.@] ne1 [)`({.@] ne2 [)@.({:@] ) nei

ni =: [:(<./,]i.<./)(;:'S SE SW') i.~ ]
n0 =: a:-.~(a:"_)`(0,{.@[)`]}
n1 =: a:-.~(('NE';a:)"_)`(0,{.@[)`]}
n2 =: a:-.~(('NW';a:)"_)`(0,{.@[)`]}
na =: ({.@] n0 [)`({.@] n1 [)`({.@] n2 [)@.({:@] ) ni

si =: [:(<./,]i.<./)(;:'N SE SW') i.~ ]
s0 =: a:-.~(a:"_)`(0,{.@[)`]}
s1 =: a:-.~(('SE';a:)"_)`(0,{.@[)`]}
s2 =: a:-.~(('SW';a:)"_)`(0,{.@[)`]}
sa =: ({.@] s0 [)`({.@] s1 [)`({.@] s2 [)@.({:@] ) si

all =: na`sa`nea`sea`nwa`swa@.(dirs@{.)
dirs =: (;:'N S NE SE NW SW')&i.


​If you've gotten this far, you may be interested in an
anomaly that turned up when further analyzing the results
in `test`: i. could NOT locate the first <'N' in test,
although i. successfully found the other 2 nub elements.

   #;:test2 =: ((all :: ])&. ;:)^: _ test
939
   (<'NE') i.~;: test
0
   (<'SE') i.~;: test
649
   (<'N') i.~;: test       NB. this result should be < 939
939​



On Fri, Dec 15, 2017 at 6:52 PM, Raul Miller <[email protected]> wrote:

> Like this?
>
>    ({.@ni n0`n1`n2@.({:@ni) ]) ;:2}.ex1
> ┌─┬──┬──┬──┬──┬──┬──┐
> │N│NW│NW│NE│NE│SW│SW│
> └─┴──┴──┴──┴──┴──┴──┘
>
> Or, if you do not like running ni twice:
>
>     (({.@] n0 [)`({.@] n1 [)`({.@] n2 [)@.({:@]) ni) ;:2}.ex1
> ┌─┬──┬──┬──┬──┬──┬──┐
> │N│NW│NW│NE│NE│SW│SW│
> └─┴──┴──┴──┴──┴──┴──┘
>
> I hope this helps,
>
> --
> Raul
>
>
>
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to