man is not so good! Then comes "Why not...."
Linda

-----Original Message-----
From: Programming <[email protected]> On Behalf Of Linda 
Alvord
Sent: Sunday, December 9, 2018 2:03 PM
To: [email protected]
Subject: Re: [Jprogramming] AOC 2018 day 6

David, It's fun to work through solutions when you can't keep up with advent 
puzzles.

How about this for manhattan?

man=:+/"2
   man DATA
26 28

(that's as far as I've gone.)

Linda
-----Original Message-----
From: Programming <[email protected]> On Behalf Of David 
Lambert
Sent: Sunday, December 9, 2018 9:14 AM
To: programming <[email protected]>
Subject: Re: [Jprogramming] AOC 2018 day 6

Day 6 2018 partial spoiler


coordinates=: (4 $. $.)@:$&1

manhattan=: [: +/ [: | -

DATA=:".;._2[0 :0
1, 1
1, 6
8, 3
3, 4
5, 5
8, 9
)

NB. 10 by 10 grid bounds the example
NB. Y is the distance from each point to each grid
Y=: DATA manhattan"1/coordinates 10 10

    NB. minimum distance from coordinates to a point
    <./Y
2 1 2 3 3 2 1 2 3 4 1 0 1 2 2 1 0 1 2 3 2 1 2 2 1 2 1 2 3 4 3 2 2 1 0 1 
2 3 4 5 4 3 3 2 1 1 2 3 4 4 5 4 3 2 1 0 1 2 3 3 5 4 3 2 2 1 2 3 3 2 4 3 
2 1 2 2 3 3 2 1 3 2 1 0 1 2 3 2 1 0 4 3 2 1 2 3 4 3 2 1

    NB. index of that minimum
    NB. which is also the point identification
    NB. need a bit more cleverness to identify equidistant sites
    (|: i."1 0 <./)Y
0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 0 3 3 1 1 1 1 1 0 0 3 3 3 3 
1 1 1 1 0 0 3 3 3 4 4 4 4 5 0 0 4 4 4 4 4 4 4 5 2 2 2 2 4 4 4 4 5 5 2 2 
2 2 2 4 4 5 5 5 2 2 2 2 2 2 2 5 5 5 2 2 2 2 2 2 2 5 5 5

    NB. reshape it

    NB. X is the id of a nearest point

    [X=: 10 10 $(|: i."1 0 <./)Y
0 0 0 0 1 1 1 1 1 1
0 0 0 0 1 1 1 1 1 1
0 0 0 3 3 1 1 1 1 1
0 0 3 3 3 3 1 1 1 1
0 0 3 3 3 4 4 4 4 5
0 0 4 4 4 4 4 4 4 5
2 2 2 2 4 4 4 4 5 5
2 2 2 2 2 4 4 5 5 5
2 2 2 2 2 2 2 5 5 5
2 2 2 2 2 2 2 5 5 5

    NB. simplified convex hull
    NB. take the nub of the edges
    [BOUNDARY=: ~.(({.,{:),[:,({.,{:)"1)X
0 1 2 5

On 12/9/18 7:00 AM, [email protected] wrote:
> Date: Sat, 8 Dec 2018 10:34:07 -0500
> From: Brian Schott<[email protected]>
> To: Programming forum<[email protected]>
> Subject: [Jprogramming] AOC 2018 day 6
> Message-ID:
>       <CAEDWnsvbk=h+fejabn2ts-pnrlgkwyj4r1hrzyhjfjnfjqc...@mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
----------------------------------------------------------------------
For information about J forums see 
https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm&amp;data=02%7C01%7C%7C8d71812d0e4547cfc9ae08d65e08eae2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636799789729004839&amp;sdata=3KcSbQeZZnGkoOU%2BKD3BgnUiIj9gHtY0Suq7RAQQqrE%3D&amp;reserved=0
----------------------------------------------------------------------
For information about J forums see 
https://nam03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm&amp;data=02%7C01%7C%7C8d71812d0e4547cfc9ae08d65e08eae2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636799789729004839&amp;sdata=3KcSbQeZZnGkoOU%2BKD3BgnUiIj9gHtY0Suq7RAQQqrE%3D&amp;reserved=0
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to