aboutsummaryrefslogtreecommitdiff
path: root/day03.rb
blob: 246d68b3530f61159df14f33ba819b6793b9ce7c (plain) (blame)
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
28
29
d = []
IO.foreach("day03") { |line|
  l = line.split(/\s*[#@,:\nx]\s*/).map(&:to_i)
  d << l[1..-1]
}

claims = d.map(&:first)

require 'set'

r = 0
p = {}
p2 = {}
d.each { |id,l,t,w,h|
  (l...l+w).each { |x|
    (t...t+h).each { |y|
      if p.include? [x,y]
        p2[[x,y]] = true
        claims.delete(p[[x,y]])
        claims.delete(id)
      else
        p[[x,y]] = id
      end
    }
  }
}

p p2.size
puts claims