Skip to content

Instantly share code, notes, and snippets.

@sarahzrf
Created December 6, 2021 03:21
Show Gist options
  • Save sarahzrf/391851d1d7cd5c840b499056dfd00752 to your computer and use it in GitHub Desktop.
Save sarahzrf/391851d1d7cd5c840b499056dfd00752 to your computer and use it in GitHub Desktop.
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