AoC2015/day12/solution.rb

22 lines
581 B
Ruby

#!/bin/env ruby
require 'pry'
require 'json'
input = File.read('./input').chomp
data = JSON.parse(input)
# I know this won't be useful for part 2 but I couldn't resist
part1 = input.scan(/-*\d{1,}/).map(&:to_i).sum
puts "Part 1 Soltuion: #{part1}"
@nums = []
def find_all_values(data)
@nums.push(data) if data.is_a?(Integer)
data.each_value { |val| find_all_values(val) } if data.is_a?(Hash) && !data.has_value?('red')
data.each { |val| find_all_values(val) } if data.is_a?(Array)
end
find_all_values(data)
part2 = @nums.sum
puts "Part 2 Soltuion: #{part2}"
# binding.pry