[Jprogramming] AoC Day 11 - something is wrong
Henry Rich
henryhrich at gmail.com
Sun Dec 17 19:57:29 UTC 2017
I haven't been following this thread but has gone on so long that I
thought I would post a solution:
NB. Input translation to N/SE/SW form
'n s ne se nw sw' =: _3 ,:\ 1 0 0 _1 0 0 0 0 _1 0 1 0 0 _1 0 0 0 1
NB. Apply transformations. We want the one transformtation that converts
the most move-pairs
NB. to single moves. The second-largest value will be the number of
pairs we can convert
xform =: (- 1 { /:~)"1
NB. Get input
input =: ". wd 'clippaste'
+/ | xform +/ input NB. part 1
>./ +/"1 | xform +/\ input NB. part 2
Henry Rich
On 12/17/2017 2:23 PM, Brian Schott wrote:
> Raul,
>
> Right, I remember now that you said that earlier
> in this thread. Obviously, I did not understand
> it then.
>
> Thanks for your patience and great help,
>
> On Sun, Dec 17, 2017 at 2:06 PM, Raul Miller <rauldmiller at gmail.com> wrote:
>
>> They are locations that are unique. And they can be converted into
>> either number of steps to that location or into a sequence of steps to
>> reach that location:
>>
>> nsteps=: +/@:|"1
>>
>> path=:3 :0
>> r=.''
>> while. 0<+/|y do.
>> pick=. (i. <./) +/"1|dss -~"1/ y
>> y=.y-pick{dss
>> r=.r,pick{nms
>> end.
>> )
>>
>> Beware, however, that arbitrary sequences of three integers (or half
>> integers) are not necessarily valid locations (we are working with a
>> two dimensional grid here, so those three numbers cannot be completely
>> independent of each other). Here's a variation of path which catches
>> that issue:
>>
>> apath=:3 :0
>> o=. y
>> r=.''
>> while. (o >:&(+/@:|) y) * 0<+/|y do.
>> o=. y
>> pick=. (i. <./) +/"1|dss -~"1/ y
>> y=.y-pick{dss
>> r=.r,pick{nms
>> end.
>> assert. 0=+/|y
>> )
>>
>>
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
---
This email has been checked for viruses by AVG.
http://www.avg.com
More information about the Programming
mailing list