I didn't bother with sparse arrays for aoc 12, but used what I think
is a similar approach:

id2num=:_ ". ] -. -.&(":i.10)

id2con=:3 :0
  nodes=: {.@id2num;._2 y
  assert. (-: i.@#) nodes
  nodes&e.@id2num;._2 y
)

tc=: (+. +./ .*~)^:_

aoc12a=:#@I.@{.@tc@id2con
aoc12b=:#@~.@:I.@tc@id2con

Good luck,

-- 
Raul


On Tue, Dec 12, 2017 at 11:40 PM, Jimmy Gauvin <[email protected]> wrote:
> 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.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to