AoC2015/day16/solution.rb

44 lines
1.1 KiB
Ruby

#!/bin/env ruby
require 'pry'
input = File.readlines('./input')
sues = input.to_h do |line|
line = line.delete(':').delete(',').split
sue = (line[0] + line[1]).to_sym
properties = line[2..-1].each_slice(2).map { |property, num| [property.to_sym, num.to_i] }.to_h
[sue, properties]
end
list = { children: 3,
cats: 7,
samoyeds: 2,
pomeranians: 3,
akitas: 0,
vizslas: 0,
goldfish: 5,
trees: 3,
cars: 2,
perfumes: 1 }
part1 = sues.map do |sue, properties|
sue if properties.map do |key, value|
list[key] == value
end.reduce(:&)
end.compact[0].to_s
puts "Part 1 Solution: #{part1}"
# binding.pry
part2 = sues.map do |sue, properties|
sue if properties.map do |key, value|
if %i[cats trees].include?(key)
list[key] < value
elsif %i[pomeranians goldfish].include?(key)
list[key] > value
else
list[key] == value
end
end.reduce(&:&)
end.compact[0].to_s
puts "Part 1 Solution: #{part2}"