Oops, sorry, you are right. Here is what I should have sent you:
dss=:-:<:3 #.inv 15 21 19 11 5 7
nms=: ;:'n ne se s sw nw'
location=:3 :0
+/dss{~nms i.y
)
Sorry about that, I should have tested it instead of just editing it
based on memory. Bad habits are bad.
Thanks,
--
Raul
On Sun, Dec 17, 2017 at 1:24 PM, Brian Schott <[email protected]> wrote:
> Raul,
>
> I see the result of `location` as being the number of steps,
> but not a grid location (as you suggest) because its result
> is simply 696 in my data's case, for example. Of course,
> that's all that AoC 11 required.
>
> My approach using Jimmy's algorithm (I think) does perhaps not
> tell the exact final location because that final location
> can apparently be reached with several different combinations
> of directions including the following. But it at least tells
> the general direction of the end result. Right?
>
> Steps
> NE N
> 696 0
> 698 1
> 697 2
> ...
> 586 110
>
> N NE N
> 110 586 0
> 109 585 1
>
> etc. (others)
>
> On the other hand, I may be wrong, and the algorithm Jimmy
> suggest DOES provide a way of telling exactly the unique
> location reached. I just cannot work out what it tells.
> Can anyone?
>
>
> On Sun, Dec 17, 2017 at 12:27 PM, Raul Miller <[email protected]> wrote:
>
>> Here's how I would interpret the final stage's result:
>>
>> dss=:-:<:3 #.inv 15 21 19 11 5 7
>> nms=: ;:'n ne se s sw nw'
>> location=:3 :0
>> {:+/||:+/\dss{~nms i.y
>> )
>>
>> This translates a symbolic sequence into a grid location. So as a
>> basic integrity check, I would run it against both your source
>> sequence and your result sequence. If the location of both is the
>> same, you are probably on the right track.
>>
>> But I think this problem requires at least two passes. If you do not
>> figure out where you are going before you try to find the shortest way
>> to get there, you wind up trying to find the shortest distance to
>> "everywhere". (And, ok, that can be a quicky description of a viable
>> algorithm, but you still wind up with multiple passes of a sort in
>> your implementation.)
>>
>> Thanks,
>>
>> --
>> Raul
>>
>>
>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm