diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-11-06 20:28:53 +0000 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-11-06 20:28:53 +0000 |
commit | d7d62da5e9c2ca991885641e0a55c2907eb0fb7e (patch) | |
tree | d7b6fca43226fe6affc57f5ef52ce461e13d18b7 /rb/day12.rb | |
parent | 46a7ef78253879ca3b5147fdd42f8789983b0b30 (diff) |
Do a bunch in ruby
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}" |