|
|
@ -1,13 +1,27 @@
|
|
|
|
p ARGF.read.lines.each.with_object(Hash.new(0)) {|line, fabric|
|
|
|
|
claims, fabric = ARGF
|
|
|
|
line =~ /(\d+),(\d+): (\d+)x(\d+)$/
|
|
|
|
.read
|
|
|
|
x = $1.to_i
|
|
|
|
.lines
|
|
|
|
y = $2.to_i
|
|
|
|
.map(&:chomp)
|
|
|
|
width = $3.to_i
|
|
|
|
.reject(&:empty?)
|
|
|
|
height = $4.to_i
|
|
|
|
.each
|
|
|
|
|
|
|
|
.with_object([[], Hash.new {|h,k| h[k] = []}]) { |line, (claims, fabric)|
|
|
|
|
|
|
|
|
line =~ /^#(\d+) @ (\d+),(\d+): (\d+)x(\d+)$/
|
|
|
|
|
|
|
|
claim = $1.to_i
|
|
|
|
|
|
|
|
x = $2.to_i
|
|
|
|
|
|
|
|
y = $3.to_i
|
|
|
|
|
|
|
|
width = $4.to_i
|
|
|
|
|
|
|
|
height = $5.to_i
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
claims << claim
|
|
|
|
width.times {|dx|
|
|
|
|
width.times {|dx|
|
|
|
|
height.times {|dy|
|
|
|
|
height.times {|dy|
|
|
|
|
fabric[[y + dy, x + dx]] += 1
|
|
|
|
fabric[[y+dy, x+dx]] << claim
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p claims.reject {|claim|
|
|
|
|
|
|
|
|
fabric.any? {|_,v|
|
|
|
|
|
|
|
|
v.length > 1 && v.include?(claim)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.count {|_,v| v > 1 }
|
|
|
|
|
|
|
|