AdventOfCode-2020/day4.cr

29 lines
544 B
Crystal
Raw Normal View History

2020-12-04 18:40:10 -08:00
require "./passports.cr"
2020-12-03 23:52:28 -08:00
INPUT = File.read("day4.txt")
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