diff options
Diffstat (limited to 'rb/day12.rb')
-rwxr-xr-x | rb/day12.rb | 28 |
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}" |