aboutsummaryrefslogtreecommitdiff
path: root/day03/part2
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2018-12-03 10:20:48 +0000
committerNat Lasseter <user@4574.co.uk>2018-12-03 10:20:48 +0000
commitc13a36eb26055d80749a862d302c208898fe049a (patch)
tree0b956fce434f6d161818dadbcb4d486e042e8e52 /day03/part2
parent782650f9f96a07c7f8a403408a2bec040e8b5f56 (diff)
Add Day03
Diffstat (limited to 'day03/part2')
-rwxr-xr-xday03/part233
1 files changed, 33 insertions, 0 deletions
diff --git a/day03/part2 b/day03/part2
new file mode 100755
index 0000000..52e26da
--- /dev/null
+++ b/day03/part2
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+
+cloth = Array.new(1000) do
+ Array.new(1000) do
+ Array.new
+ end
+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] << claim[0]
+ end
+ end
+end
+
+overlaps = Array.new(input[-1][0], false)
+
+cloth.each do |c|
+ c.each do |r|
+ if r.length > 1
+ r.each do |id|
+ overlaps[id-1] = true
+ end
+ end
+ end
+end
+
+puts overlaps.index(false) + 1