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 http://www.jsoftware.com/forums.htm

Reply via email to