Solved Day 12
parent
29fc374254
commit
09cf5efc47
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,21 @@
|
||||||
|
#!/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
|
Loading…
Reference in New Issue