Fixup day18 and add second part
[advent-of-code-2020.git] / day04 / summary.txt
1 --- Day 4: Passport Processing ---
2 You arrive at the airport only to realize that you grabbed your North Pole Credentials instead of your passport. While these documents are extremely similar, North Pole Credentials aren't issued by a country and therefore aren't actually valid documentation for travel in most of the world.
3
4 It seems like you're not the only one having problems, though; a very long line has formed for the automatic passport scanners, and the delay could upset your travel itinerary.
5
6 Due to some questionable network security, you realize you might be able to solve both of these problems at the same time.
7
8 The automatic passport scanners are slow because they're having trouble detecting which passports have all required fields. The expected fields are as follows:
9
10 byr (Birth Year)
11 iyr (Issue Year)
12 eyr (Expiration Year)
13 hgt (Height)
14 hcl (Hair Color)
15 ecl (Eye Color)
16 pid (Passport ID)
17 cid (Country ID)
18 Passport data is validated in batch files (your puzzle input). Each passport is represented as a sequence of key:value pairs separated by spaces or newlines. Passports are separated by blank lines.
19
20 Here is an example batch file containing four passports:
21
22 ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
23 byr:1937 iyr:2017 cid:147 hgt:183cm
24
25 iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
26 hcl:#cfa07d byr:1929
27
28 hcl:#ae17e1 iyr:2013
29 eyr:2024
30 ecl:brn pid:760753108 byr:1931
31 hgt:179cm
32
33 hcl:#cfa07d eyr:2025 pid:166559648
34 iyr:2011 ecl:brn hgt:59in
35 The first passport is valid - all eight fields are present. The second passport is invalid - it is missing hgt (the Height field).
36
37 The third passport is interesting; the only missing field is cid, so it looks like data from North Pole Credentials, not a passport at all! Surely, nobody would mind if you made the system temporarily ignore missing cid fields. Treat this "passport" as valid.
38
39 The fourth passport is missing two fields, cid and byr. Missing cid is fine, but missing any other field is not, so this passport is invalid.
40
41 According to the above rules, your improved system would report 2 valid passports.
42
43 Count the number of valid passports - those that have all required fields. Treat cid as optional. In your batch file, how many passports are valid?
44
45 Your puzzle answer was 254.
46
47 --- Part Two ---
48 The line is moving more quickly now, but you overhear airport security talking about how passports with invalid data are getting through. Better add some data validation, quick!
49
50 You can continue to ignore the cid field, but each other field has strict rules about what values are valid for automatic validation:
51
52 byr (Birth Year) - four digits; at least 1920 and at most 2002.
53 iyr (Issue Year) - four digits; at least 2010 and at most 2020.
54 eyr (Expiration Year) - four digits; at least 2020 and at most 2030.
55 hgt (Height) - a number followed by either cm or in:
56 If cm, the number must be at least 150 and at most 193.
57 If in, the number must be at least 59 and at most 76.
58 hcl (Hair Color) - a # followed by exactly six characters 0-9 or a-f.
59 ecl (Eye Color) - exactly one of: amb blu brn gry grn hzl oth.
60 pid (Passport ID) - a nine-digit number, including leading zeroes.
61 cid (Country ID) - ignored, missing or not.
62 Your job is to count the passports where all required fields are both present and valid according to the above rules. Here are some example values:
63
64 byr valid:   2002
65 byr invalid: 2003
66
67 hgt valid:   60in
68 hgt valid:   190cm
69 hgt invalid: 190in
70 hgt invalid: 190
71
72 hcl valid:   #123abc
73 hcl invalid: #123abz
74 hcl invalid: 123abc
75
76 ecl valid:   brn
77 ecl invalid: wat
78
79 pid valid:   000000001
80 pid invalid: 0123456789
81 Here are some invalid passports:
82
83 eyr:1972 cid:100
84 hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926
85
86 iyr:2019
87 hcl:#602927 eyr:1967 hgt:170cm
88 ecl:grn pid:012533040 byr:1946
89
90 hcl:dab227 iyr:2012
91 ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277
92
93 hgt:59cm ecl:zzz
94 eyr:2038 hcl:74454a iyr:2023
95 pid:3556412378 byr:2007
96 Here are some valid passports:
97
98 pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980
99 hcl:#623a2f
100
101 eyr:2029 ecl:blu cid:129 byr:1989
102 iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm
103
104 hcl:#888785
105 hgt:164cm byr:2001 iyr:2015 cid:88
106 pid:545766238 ecl:hzl
107 eyr:2022
108
109 iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
110 Count the number of valid passports - those that have all required fields and valid values. Continue to treat cid as optional. In your batch file, how many passports are valid?
111
112 Your puzzle answer was 184.
113
114 Both parts of this puzzle are complete! They provide two gold stars: **
115
116 At this point, you should return to your Advent calendar and try another puzzle.
117
118 If you still want to see it, you can get your puzzle input.
119
120 You can also [Share] this puzzle.