aboutsummaryrefslogtreecommitdiff
path: root/rb/day12.rb
diff options
context:
space:
mode:
Diffstat (limited to 'rb/day12.rb')
-rwxr-xr-xrb/day12.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/rb/day12.rb b/rb/day12.rb
new file mode 100755
index 0000000..96fef5f
--- /dev/null
+++ b/rb/day12.rb
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+
+input = File.read("day12.input")
+
+puts "Part 1: #{input.scan(/-?\d+/).map(&:to_i).sum}"
+
+require 'json'
+json = JSON.parse(input)
+
+search = [json]
+sum = 0
+
+until search.empty?
+ this = search.shift
+ case this
+ when Numeric
+ sum += this
+ when Array
+ search.push(*this)
+ when Hash
+ unless this.values.include?("red")
+ search.push(*this.keys)
+ search.push(*this.values)
+ end
+ end
+end
+
+puts "Part 2: #{sum}"