aboutsummaryrefslogtreecommitdiff
path: root/day03/part1
blob: 79b9d85988d2a3cb704fa8d84a7c8e69698ebc42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env ruby

cloth = Array.new(1000) do
  Array.new(1000, 0)
end

input = $stdin.readlines.map(&:chomp).map do |x|
  /#(\d+) @ (\d+),(\d+): (\d+)x(\d+)/.match(x).captures.map(&:to_i)
end

input.each do |claim|
  (claim[1]...(claim[1]+claim[3])).each do |c|
    (claim[2]...(claim[2]+claim[4])).each do |r|
      cloth[c][r] += 1
    end
  end
end

clashes = 0

cloth.each do |c|
  c.each do |r|
    clashes += 1 if r > 1
  end
end

puts clashes