[2023][ruby][16.2] shameless green

main
Alpha Chen 11 months ago
parent b7a02fda85
commit efda4ecb16
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -3,10 +3,11 @@ input = ARGF.readlines(chomp: true)
row.chars.map.with_index {|elem, x| [[y,x], elem] }
}.to_h
current = [[[0,0], [0,1]]]
seen = Set.new
count_energized = ->(start, dir) {
current = [[start, dir]]
seen = Set.new
until current.empty?
until current.empty?
coord, delta = current.shift
seen << [coord, delta]
@ -42,6 +43,19 @@ until current.empty?
end
current = current.reject { seen.include?(_1) }
end
end
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 seen.map(&:first).select { input.has_key?(_1) }.uniq.size
p candidates.map { count_energized[*_1] }.max

Loading…
Cancel
Save