AdventOfCode-2020/day4.cr

28 lines
525 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)
total = passports.count do |passport|
2020-12-04 18:40:10 -08:00
DEFAULT_VALIDATORS.all? do |k, v|
2020-12-03 23:52:28 -08:00
passport[k]?.try { |s| v.call(s) }
2020-12-03 21:22:52 -08:00
end
end
puts total
end
part1
part2