|
|
@ -3,7 +3,8 @@ input = ARGF.readlines(chomp: true)
|
|
|
|
row.chars.map.with_index {|elem, x| [[y,x], elem] }
|
|
|
|
row.chars.map.with_index {|elem, x| [[y,x], elem] }
|
|
|
|
}.to_h
|
|
|
|
}.to_h
|
|
|
|
|
|
|
|
|
|
|
|
current = [[[0,0], [0,1]]]
|
|
|
|
count_energized = ->(start, dir) {
|
|
|
|
|
|
|
|
current = [[start, dir]]
|
|
|
|
seen = Set.new
|
|
|
|
seen = Set.new
|
|
|
|
|
|
|
|
|
|
|
|
until current.empty?
|
|
|
|
until current.empty?
|
|
|
@ -44,4 +45,17 @@ until current.empty?
|
|
|
|
current = current.reject { seen.include?(_1) }
|
|
|
|
current = current.reject { seen.include?(_1) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
p seen.map(&:first).select { input.has_key?(_1) }.uniq.size
|
|
|
|
seen.map(&:first).select { input.has_key?(_1) }.uniq.size
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
max_y = input.keys.map(&:first).max
|
|
|
|
|
|
|
|
max_x = input.keys.map(&:last).max
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
candidates = [
|
|
|
|
|
|
|
|
(0..max_x).map { [[0,_1], [1,0]] }, # down
|
|
|
|
|
|
|
|
(0..max_x).map { [[max_y,_1], [-1,0]] }, # up
|
|
|
|
|
|
|
|
(0..max_y).map { [[_1,0], [0,1]] }, # right
|
|
|
|
|
|
|
|
(0..max_y).map { [[_1,max_x], [0,-1]] }, # left
|
|
|
|
|
|
|
|
].inject(:+)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p candidates.map { count_energized[*_1] }.max
|
|
|
|