Solved Day 12

main
s00ner 2022-07-17 15:23:14 -04:00
parent 29fc374254
commit 09cf5efc47
2 changed files with 22 additions and 0 deletions

1
day12/input Normal file

File diff suppressed because one or more lines are too long

21
day12/solution.rb Normal file
View File

@ -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