[Jprogramming] AoC Day 11 - something is wrong
Raul Miller
rauldmiller at gmail.com
Tue Dec 12 16:34:57 UTC 2017
Unfortunately, this is solving the wrong problem - need to count
steps, not measure distance.
In other words, these two examples wind up in the same location and
should give the same answers (18 for the steps to reach that location
and for the furthest number of steps to reach that location):
ex1=:10 8 2#;:'se ne s'
ex2=:12 6 #;:'se ne'
FYI,
--
Raul
On Tue, Dec 12, 2017 at 10:56 AM, 'Mike Day' via Programming
<programming at jsoftware.com> wrote:
> MIne isn't quite so subtle:
>
> I didn't get round to naming functions, only the constants:
>
> compass =: ;:'n nw sw s se ne'
>
> NB. I started with 0j2 _2j1 etc, but found this slightly easier:
>
> dir =: 0 _2 _2 0 2 2 ,. 2 1 _1 _2 _1 1 NB. avoiding fractions
>
>
> ex1 =: ','cut'ne,ne,ne' NB. given examples
>
> ex2 =: ','cut'ne,ne,sw,sw'
>
> ex3 =: ','cut'ne,ne,s,s'
>
> ex4 =: ','cut'se,sw,se,sw,sw'
>
>
> (+/@:((0 2,:2 1)%.~])) every 13 : '|+/dir {~compass i.y' each
> ex1;ex2;ex3;<ex4
>
> 3 0 2 3
>
>
> NB. --- Part One ---
>
>
> (+/@:((0 2,:2 1)%.~])) 13 : '|+/dir {~compass i.y' ','cut input11
>
> ...... NB. unspoilt, just in case!
>
>
> NB. --- Part Two ---
>
>
> >./(+/@:((0 2,:2 1)%.~]))"1] 13 : '|+/\dir {~compass i.y' ','cut input11
>
> ...... NB. unspoilt, just in case!
>
> Cheers,
>
> Mike
>
>
>
>
> On 11/12/2017 20:54, Jimmy Gauvin wrote:
>>
>> Hi,
>>
>> I used axial coordinates from https://www.redblobgames.com/grids/hexagons/
>> to get thru part 1.
>> Will do part 2 tonite.
>>
>> >./ | +/hxv {~ dbd i. <;._1 ',', dbi
>> 675
>>
>> where :
>>
>> dbi=: }: fread 'C:\Downloads\day11inp'
>> dbd=: ;:'n s ne nw se sw'
>> hxv =: 6 2 $ 0 _1 0 1 1 _1 _1 0 1 0 _1 1
>> dbd,.<"1 hxv
>> ┌──┬────┐
>> │n │0 _1│
>> ├──┼────┤
>> │s │0 1 │
>> ├──┼────┤
>> │ne│1 _1│
>> ├──┼────┤
>> │nw│_1 0│
>> ├──┼────┤
>> │se│1 0 │
>> ├──┼────┤
>> │sw│_1 1│
>> └──┴────┘
>>
>>
>> \ n /
>> nw +--+ ne
>> / \
>> -+ +-
>> \ /
>> sw +--+ se
>> / s \
>>
>>
>> On Mon, Dec 11, 2017 at 12:43 PM, Raul Miller <rauldmiller at gmail.com>
>> 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
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list