Created
December 6, 2021 03:21
-
-
Save sarahzrf/391851d1d7cd5c840b499056dfd00752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lines = $<.map do |l| | |
l =~ /(\d+),(\d+) -> (\d+),(\d+)/ | |
[[$1.to_i, $2.to_i], [$3.to_i, $4.to_i]] | |
end | |
map = Hash.new(0) | |
lines.each do |(x1, y1), (x2, y2)| | |
if x1 == x2 | |
x = x1 | |
(y1..y2).each do |y| | |
map[[x, y]] += 1 | |
end | |
elsif y1 == y2 | |
y = y1 | |
(x1..x2).each do |x| | |
map[[x, y]] += 1 | |
end | |
end | |
end | |
danger = map.count {|k, v| v > 1} | |
print danger | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment