AdventOfCode-2020/day4.cr

30 lines
554 B
Crystal
Raw Normal View History

2020-12-04 18:40:10 -08:00
require "./passports.cr"
2020-12-05 16:06:51 -08:00
require "advent"
INPUT = input(2020, 4)
2020-12-03 21:22:52 -08:00
2020-12-03 21:41:49 -08:00
def part1
input = INPUT.clone
passports = parse_passports(input)
total = passports.count do |passport|
["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"].all? do |key|
passport.has_key? key
2020-12-03 21:22:52 -08:00
end
2020-12-03 21:41:49 -08:00
end
puts total
end
2020-12-03 21:22:52 -08:00
2020-12-03 21:41:49 -08:00
def part2
input = INPUT.clone
passports = parse_passports(input)
2020-12-04 19:54:14 -08:00
valid_passports = [] of Passport
passports.each do |p|
if vp = Passport.from_hash?(p)
valid_passports << vp
2020-12-03 21:22:52 -08:00
end
end
2020-12-04 19:54:14 -08:00
puts valid_passports.size
2020-12-03 21:22:52 -08:00
end
part1
part2