[2023][ruby][10.x] lol

main
Alpha Chen 5 months ago
parent 95a6798f7f
commit a3706096c3
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -79,7 +79,7 @@ p loop_.size / 2
# part two
y_range, x_range = *loop_.extents
p y_range.map {|y|
p y_range.sum {|y|
x_range.chunk_while {|x_a, x_b|
a = loop_.fetch([y, x_a], nil)
b = loop_.fetch([y, x_b], nil)
@ -93,12 +93,8 @@ p y_range.map {|y|
# only keep pipes that cross the horizontal axis
deltas = end_tiles.flat_map {|tile| TILE_NEIGHBOR_DELTAS.fetch(tile) }
[[-1,0], [1,0]].all? {|dy| deltas.include?(dy) }
}.inject([false, 0]) {|(enclosed, count), chunk|
start_tile = loop_.fetch([y,chunk[0]], nil)
if start_tile.nil?
[enclosed, count + (enclosed ? chunk.size : 0)]
else
[!enclosed, count]
end
}.sum {|chunk|
tiles = chunk.map {|x| loop_.fetch([y,x], nil) }
(tiles[0]...tiles[0]) ? tiles.count(nil) : 0 # lol
}
}.sum(&:last)
}

Loading…
Cancel
Save