|
|
@ -11,38 +11,28 @@ count_energized = ->(start, dir) {
|
|
|
|
coord, delta = current.shift
|
|
|
|
coord, delta = current.shift
|
|
|
|
seen << [coord, delta]
|
|
|
|
seen << [coord, delta]
|
|
|
|
|
|
|
|
|
|
|
|
case [elem = input[coord], delta]
|
|
|
|
next_delta = case [input[coord], delta]
|
|
|
|
in [nil, _]
|
|
|
|
in [nil, _]
|
|
|
|
# the beam has escaped the contraption
|
|
|
|
[] # the beam has escaped the contraption
|
|
|
|
in [?., _] | [?|, [_,0]] | [?-, [0,_]] # keep going
|
|
|
|
in [?., _] | [?|, [_,0]] | [?-, [0,_]] # keep going
|
|
|
|
current << [coord.zip(delta).map { _1 + _2 }, delta]
|
|
|
|
[delta]
|
|
|
|
in [?|, [0,_]] # split up and down
|
|
|
|
in [?|, [0,_]] # split up and down
|
|
|
|
current << [coord.zip([-1,0]).map { _1 + _2 }, [-1,0]]
|
|
|
|
[[-1,0], [1,0]]
|
|
|
|
current << [coord.zip([1,0]).map { _1 + _2 }, [1,0]]
|
|
|
|
in [?-, [_,0]] # split left and right
|
|
|
|
in [?-, [_,0]] # split left and right
|
|
|
|
[[0,-1], [0,1]]
|
|
|
|
current << [coord.zip([0,-1]).map { _1 + _2 }, [0,-1]]
|
|
|
|
in [?/, _]
|
|
|
|
current << [coord.zip([0,1]).map { _1 + _2 }, [0,1]]
|
|
|
|
[delta.map { -_1 }.reverse]
|
|
|
|
in [?/, [0,1]] # going right, goes up
|
|
|
|
in [?\\, _]
|
|
|
|
current << [coord.zip([-1,0]).map { _1 + _2 }, [-1,0]]
|
|
|
|
[delta.reverse]
|
|
|
|
in [?/, [0,-1]] # going left, goes down
|
|
|
|
else
|
|
|
|
current << [coord.zip([1,0]).map { _1 + _2 }, [1,0]]
|
|
|
|
fail
|
|
|
|
in [?/, [1,0]] # going down, goes left
|
|
|
|
end
|
|
|
|
current << [coord.zip([0,-1]).map { _1 + _2 }, [0,-1]]
|
|
|
|
|
|
|
|
in [?/, [-1,0]] # going up, goes right
|
|
|
|
current.concat(
|
|
|
|
current << [coord.zip([0,1]).map { _1 + _2 }, [0,1]]
|
|
|
|
next_delta
|
|
|
|
in [?\\, [0,1]] # going right, goes down
|
|
|
|
.map {|d| [coord.zip(d).map { _1 + _2 }, d] }
|
|
|
|
current << [coord.zip([1,0]).map { _1 + _2 }, [1,0]]
|
|
|
|
.reject { seen.include?(_1) }
|
|
|
|
in [?\\, [0,-1]] # going left, goes up
|
|
|
|
)
|
|
|
|
current << [coord.zip([-1,0]).map { _1 + _2 }, [-1,0]]
|
|
|
|
|
|
|
|
in [?\\, [1,0]] # going down, goes right
|
|
|
|
|
|
|
|
current << [coord.zip([0,1]).map { _1 + _2 }, [0,1]]
|
|
|
|
|
|
|
|
in [?\\, [-1,0]] # going up, goes left
|
|
|
|
|
|
|
|
current << [coord.zip([0,-1]).map { _1 + _2 }, [0,-1]]
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
fail "unexpected element: #{elem.inspect}"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
current = current.reject { seen.include?(_1) }
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
seen.map(&:first).select { input.has_key?(_1) }.uniq.size
|
|
|
|
seen.map(&:first).select { input.has_key?(_1) }.uniq.size
|
|
|
|