[Jprogramming] AOC Day 12 and sparse arrays

Jimmy Gauvin jimmy.gauvin at gmail.com
Wed Dec 13 04:40:06 UTC 2017


HI all,

this AOC challenge is great for trying out J cool features, like sparse
arrays which I haven't used to date.

For part 1 I decided to try transitive closure on a sparse matrix.

Initializing the sparse array went ok but the transitive closure produced a
big bang and J just died on me, 8-(

So I went for a brute force approach : visiting all predecessors to node.

   d12=: <&;:;.(_2) 1!:1 <'/day12inp'
   d12c=:".&; each 4}. each d12

   nodto =: 3 : 0
~. y , ; y { d12c
)

   $nodto ^:_  (0)
169


There must be a nicer way to write this code.


More information about the Programming mailing list