So... I figured it out.
16#<'se' is 16 steps from the origin
10 8#<'se ne' is 18 steps from the origin but has a geometric distance
of about 14.73
So, since I was looking at the straight line distance, I was not
counting steps. And using manhattan distance is actually the right
approach.
In other words, this:
dss=:<:3 #.inv 15 21 19 11 5 7
nms=: ;:'n ne se s sw nw'
a11=:3 :0
({:,>./)-:+/||:+/\dss{~nms i.y
)
(":dss),.' ',.>nms
0 1 _1 n
1 0 _1 ne
1 _1 0 se
0 _1 1 s
_1 0 1 sw
_1 1 0 nw
dss produce a manhattan distance of 2 for each step, and is arranged
so that opposite directions cancel each other out.
Obvious once you understand it... but not immediately obvious how to
reason this way in the first place.
Thanks,
--
Raul
On Mon, Dec 11, 2017 at 12:43 PM, Raul Miller <[email protected]> wrote:
> I've been struggling with AoC day 11 - either AoC's implementation is
> wrong, or mine is.
>
> Here's my implementation:
>
> nms=: ;:'n ne se s sw nw'
> dir=: ^j.2p1*(%~ i.)#nms
>
> delta=: dir {~ nms i. ]
>
> location=: +/@delta
> furthest=: [: ({~ (i. >./)@:|) +/\@delta
> path=:3 :0
> nms {~(|: i."_1 <./)|dir -/ 2-/\(- dir&([ {~ [: (i. >./) +/
> .*&.+.))^:(0.5 <|)^:a: y
> )
> showpath=:3 :0
> p=. path y
> echo 'steps: ',":#p
> echo (":,.#/.~p),.' ',.>~.p
> )
>
> And here's a translation to python along with a request for help:
>
> https://www.reddit.com/r/adventofcode/comments/7izym2/2017_day_11_solutions/dr36ujj/
>
> I suppose I might retranslate the python implementation of path back
> into J, but they both give the same answer, so I'm convinced that
> that's not the issue.
>
> So far, it's only been a few hours, but I've not gotten any real
> feedback from reddit, and I've gone over this enough times that I'm
> convinced that if I screwed up I've got such a big blind spot that I'm
> not going to see through the problem today.
>
> Anyways... if anyone else has some insight here (and/or a better
> implementation), I'd love to see it.
>
> Thanks,
>
> --
> Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm