Done day 10
[advent-of-code-20.git] / problems / day04.html
1 <!DOCTYPE html>
2 <html lang="en-us">
3 <head>
4 <meta charset="utf-8"/>
5 <title>Day 4 - Advent of Code 2020</title>
6 <!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
7 <link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'/>
8 <link rel="stylesheet" type="text/css" href="/static/style.css?25"/>
9 <link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
10 <link rel="shortcut icon" href="/favicon.png"/>
11 </head><!--
12
13
14
15
16 Oh, hello! Funny seeing you here.
17
18 I appreciate your enthusiasm, but you aren't going to find much down here.
19 There certainly aren't clues to any of the puzzles. The best surprises don't
20 even appear in the source until you unlock them for real.
21
22 Please be careful with automated requests; I'm not a massive company, and I can
23 only take so much traffic. Please be considerate so that everyone gets to play.
24
25 If you're curious about how Advent of Code works, it's running on some custom
26 Perl code. Other than a few integrations (auth, analytics, social media), I
27 built the whole thing myself, including the design, animations, prose, and all
28 of the puzzles.
29
30 The puzzles are most of the work; preparing a new calendar and a new set of
31 puzzles each year takes all of my free time for 4-5 months. A lot of effort
32 went into building this thing - I hope you're enjoying playing it as much as I
33 enjoyed making it for you!
34
35 If you'd like to hang out, I'm @ericwastl on Twitter.
36
37 - Eric Wastl
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 -->
89 <body>
90 <header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2020/about">[About]</a></li><li><a href="/2020/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2020/settings">[Settings]</a></li><li><a href="/2020/auth/logout">[Log Out]</a></li></ul></nav><div class="user">Neil Smith <a href="/2020/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">8*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">0x0000|</span><a href="/2020">2020</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2020">[Calendar]</a></li><li><a href="/2020/support">[AoC++]</a></li><li><a href="/2020/sponsors">[Sponsors]</a></li><li><a href="/2020/leaderboard">[Leaderboard]</a></li><li><a href="/2020/stats">[Stats]</a></li></ul></nav></div></header>
91
92 <div id="sidebar">
93 <div id="sponsor"><div class="quiet">Our <a href="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://medium.com/building-trayio" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">tray.io</a> - Building a platform that connects people with technology.</div></div>
94 </div><!--/sidebar-->
95
96 <main>
97 <script>window.addEventListener('click', function(e,s,r){if(e.target.nodeName==='CODE'&&e.detail===3){s=window.getSelection();s.removeAllRanges();r=document.createRange();r.selectNodeContents(e.target);s.addRange(r);}});</script>
98 <article class="day-desc"><h2>--- Day 4: Passport Processing ---</h2><p>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.</p>
99 <p>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.</p>
100 <p>Due to some questionable network security, you realize you might be able to solve both of these problems at the same time.</p>
101 <p>The automatic passport scanners are slow because they're having trouble <em>detecting which passports have all required fields</em>. The expected fields are as follows:</p>
102 <ul>
103 <li><code>byr</code> (Birth Year)</li>
104 <li><code>iyr</code> (Issue Year)</li>
105 <li><code>eyr</code> (Expiration Year)</li>
106 <li><code>hgt</code> (Height)</li>
107 <li><code>hcl</code> (Hair Color)</li>
108 <li><code>ecl</code> (Eye Color)</li>
109 <li><code>pid</code> (Passport ID)</li>
110 <li><code>cid</code> (Country ID)</li>
111 </ul>
112 <p>Passport data is validated in batch files (your puzzle input). Each passport is represented as a sequence of <code>key:value</code> pairs separated by spaces or newlines. Passports are separated by blank lines.</p>
113 <p>Here is an example batch file containing four passports:</p>
114 <pre><code>ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
115 byr:1937 iyr:2017 cid:147 hgt:183cm
116
117 iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
118 hcl:#cfa07d byr:1929
119
120 hcl:#ae17e1 iyr:2013
121 eyr:2024
122 ecl:brn pid:760753108 byr:1931
123 hgt:179cm
124
125 hcl:#cfa07d eyr:2025 pid:166559648
126 iyr:2011 ecl:brn hgt:59in
127 </code></pre>
128 <p>The first passport is <em>valid</em> - all eight fields are present. The second passport is <em>invalid</em> - it is missing <code>hgt</code> (the Height field).</p>
129 <p>The third passport is interesting; the <em>only missing field</em> is <code>cid</code>, 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 <code>cid</code> fields. Treat this "passport" as <em>valid</em>.</p>
130 <p>The fourth passport is missing two fields, <code>cid</code> and <code>byr</code>. Missing <code>cid</code> is fine, but missing any other field is not, so this passport is <em>invalid</em>.</p>
131 <p>According to the above rules, your improved system would report <code><em>2</em></code> valid passports.</p>
132 <p>Count the number of <em>valid</em> passports - those that have all required fields. Treat <code>cid</code> as optional. <em>In your batch file, how many passports are valid?</em></p>
133 </article>
134 <p>Your puzzle answer was <code>247</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>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!</p>
135 <p>You can continue to ignore the <code>cid</code> field, but each other field has <span title="GLORY TO ARSTOTZKA">strict rules</span> about what values are valid for automatic validation:</p>
136 <ul>
137 <li><code>byr</code> (Birth Year) - four digits; at least <code>1920</code> and at most <code>2002</code>.</li>
138 <li><code>iyr</code> (Issue Year) - four digits; at least <code>2010</code> and at most <code>2020</code>.</li>
139 <li><code>eyr</code> (Expiration Year) - four digits; at least <code>2020</code> and at most <code>2030</code>.</li>
140 <li><code>hgt</code> (Height) - a number followed by either <code>cm</code> or <code>in</code>:
141 <ul>
142 <li>If <code>cm</code>, the number must be at least <code>150</code> and at most <code>193</code>.</li>
143 <li>If <code>in</code>, the number must be at least <code>59</code> and at most <code>76</code>.</li>
144 </ul>
145 </li>
146 <li><code>hcl</code> (Hair Color) - a <code>#</code> followed by exactly six characters <code>0</code>-<code>9</code> or <code>a</code>-<code>f</code>.</li>
147 <li><code>ecl</code> (Eye Color) - exactly one of: <code>amb</code> <code>blu</code> <code>brn</code> <code>gry</code> <code>grn</code> <code>hzl</code> <code>oth</code>.</li>
148 <li><code>pid</code> (Passport ID) - a nine-digit number, including leading zeroes.</li>
149 <li><code>cid</code> (Country ID) - ignored, missing or not.</li>
150 </ul>
151 <p>Your job is to count the passports where all required fields are both <em>present</em> and <em>valid</em> according to the above rules. Here are some example values:</p>
152 <pre><code>byr valid: 2002
153 byr invalid: 2003
154
155 hgt valid: 60in
156 hgt valid: 190cm
157 hgt invalid: 190in
158 hgt invalid: 190
159
160 hcl valid: #123abc
161 hcl invalid: #123abz
162 hcl invalid: 123abc
163
164 ecl valid: brn
165 ecl invalid: wat
166
167 pid valid: 000000001
168 pid invalid: 0123456789
169 </code></pre>
170 <p>Here are some invalid passports:</p>
171 <pre><code>eyr:1972 cid:100
172 hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926
173
174 iyr:2019
175 hcl:#602927 eyr:1967 hgt:170cm
176 ecl:grn pid:012533040 byr:1946
177
178 hcl:dab227 iyr:2012
179 ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277
180
181 hgt:59cm ecl:zzz
182 eyr:2038 hcl:74454a iyr:2023
183 pid:3556412378 byr:2007
184 </code></pre>
185 <p>Here are some valid passports:</p>
186 <pre><code>pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980
187 hcl:#623a2f
188
189 eyr:2029 ecl:blu cid:129 byr:1989
190 iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm
191
192 hcl:#888785
193 hgt:164cm byr:2001 iyr:2015 cid:88
194 pid:545766238 ecl:hzl
195 eyr:2022
196
197 iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
198 </code></pre>
199 <p>Count the number of <em>valid</em> passports - those that have all required fields <em>and valid values</em>. Continue to treat <code>cid</code> as optional. <em>In your batch file, how many passports are valid?</em></p>
200 </article>
201 <p>Your puzzle answer was <code>145</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
202 <p>At this point, you should <a href="/2020">return to your Advent calendar</a> and try another puzzle.</p>
203 <p>If you still want to see it, you can <a href="4/input" target="_blank">get your puzzle input</a>.</p>
204 <p>You can also <span class="share">[Share<span class="share-content">on
205 <a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Passport+Processing%22+%2D+Day+4+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F4&amp;related=ericwastl&amp;hashtags=AdventOfCode" target="_blank">Twitter</a>
206 <a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=I%27ve+completed+%22Passport+Processing%22+%2D+Day+4+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F4'}else{return false;}" target="_blank">Mastodon</a
207 ></span>]</span> this puzzle.</p>
208 </main>
209
210 <!-- ga -->
211 <script>
212 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
213 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
214 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
215 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
216 ga('create', 'UA-69522494-1', 'auto');
217 ga('set', 'anonymizeIp', true);
218 ga('send', 'pageview');
219 </script>
220 <!-- /ga -->
221 </body>
222 </html>