aboutsummaryrefslogtreecommitdiff
path: root/day03.rb
diff options
context:
space:
mode:
Diffstat (limited to 'day03.rb')
-rw-r--r--day03.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/day03.rb b/day03.rb
new file mode 100644
index 0000000..246d68b
--- /dev/null
+++ b/day03.rb
@@ -0,0 +1,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