Raul's code works fine until you try applying it to a "sparse" array.
This is the result of his transitive closure applied to the adjacency
matrix
for the example provided, the one with 7 nodes and 2 connected groups:
tc adjex12
1 0 1 1 1 1 1
0 1 0 0 0 0 0
1 0 1 1 1 1 1
1 0 1 1 1 1 1
1 0
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 lu
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-(