I appreciate your enthusiasm, but you aren't going to find much down here.
There certainly aren't clues to any of the puzzles. The best surprises don't
even appear in the source until you unlock them for real.
Please be careful with automated requests; I'm not a massive company, and I can
only take so much traffic. Please be considerate so that everyone gets to play.
If you're curious about how Advent of Code works, it's running on some custom
Perl code. Other than a few integrations (auth, analytics, social media), I
built the whole thing myself, including the design, animations, prose, and all
of the puzzles.
The puzzles are most of the work; preparing a new calendar and a new set of
puzzles each year takes all of my free time for 4-5 months. A lot of effort
went into building this thing - I hope you're enjoying playing it as much as I
enjoyed making it for you!
If you'd like to hang out, I'm @ericwastl on Twitter.
- Eric Wastl
-->
<body>
<header><div><h1class="title-global"><ahref="/">Advent of Code</a></h1><nav><ul><li><ahref="/2020/about">[About]</a></li><li><ahref="/2020/events">[Events]</a></li><li><ahref="https://teespring.com/stores/advent-of-code"target="_blank">[Shop]</a></li><li><ahref="/2020/settings">[Settings]</a></li><li><ahref="/2020/auth/logout">[Log Out]</a></li></ul></nav><divclass="user">Neil Smith <ahref="/2020/support"class="supporter-badge"title="Advent of Code Supporter">(AoC++)</a><spanclass="star-count">8*</span></div></div><div><h1class="title-event"> <spanclass="title-event-wrap">0x0000|</span><ahref="/2020">2020</a><spanclass="title-event-wrap"></span></h1><nav><ul><li><ahref="/2020">[Calendar]</a></li><li><ahref="/2020/support">[AoC++]</a></li><li><ahref="/2020/sponsors">[Sponsors]</a></li><li><ahref="/2020/leaderboard">[Leaderboard]</a></li><li><ahref="/2020/stats">[Stats]</a></li></ul></nav></div></header>
<divid="sidebar">
<divid="sponsor"><divclass="quiet">Our <ahref="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><divclass="sponsor"><ahref="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>
<articleclass="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>
<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>
<p>Due to some questionable network security, you realize you might be able to solve both of these problems at the same time.</p>
<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>
<ul>
<li><code>byr</code> (Birth Year)</li>
<li><code>iyr</code> (Issue Year)</li>
<li><code>eyr</code> (Expiration Year)</li>
<li><code>hgt</code> (Height)</li>
<li><code>hcl</code> (Hair Color)</li>
<li><code>ecl</code> (Eye Color)</li>
<li><code>pid</code> (Passport ID)</li>
<li><code>cid</code> (Country ID)</li>
</ul>
<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>
<p>Here is an example batch file containing four passports:</p>
<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>
<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>
<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>
<p>According to the above rules, your improved system would report <code><em>2</em></code> valid passports.</p>
<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>
</article>
<p>Your puzzle answer was <code>247</code>.</p><articleclass="day-desc"><h2id="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>
<p>You can continue to ignore the <code>cid</code> field, but each other field has <spantitle="GLORY TO ARSTOTZKA">strict rules</span> about what values are valid for automatic validation:</p>
<ul>
<li><code>byr</code> (Birth Year) - four digits; at least <code>1920</code> and at most <code>2002</code>.</li>
<li><code>iyr</code> (Issue Year) - four digits; at least <code>2010</code> and at most <code>2020</code>.</li>
<li><code>eyr</code> (Expiration Year) - four digits; at least <code>2020</code> and at most <code>2030</code>.</li>
<li><code>hgt</code> (Height) - a number followed by either <code>cm</code> or <code>in</code>:
<ul>
<li>If <code>cm</code>, the number must be at least <code>150</code> and at most <code>193</code>.</li>
<li>If <code>in</code>, the number must be at least <code>59</code> and at most <code>76</code>.</li>
</ul>
</li>
<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>
<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>
<li><code>pid</code> (Passport ID) - a nine-digit number, including leading zeroes.</li>
<li><code>cid</code> (Country ID) - ignored, missing or not.</li>
</ul>
<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>
<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>
</article>
<p>Your puzzle answer was <code>145</code>.</p><pclass="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
<p>At this point, you should <ahref="/2020">return to your Advent calendar</a> and try another puzzle.</p>
<p>If you still want to see it, you can <ahref="4/input"target="_blank">get your puzzle input</a>.</p>
<p>You can also <spanclass="share">[Share<spanclass="share-content">on
I appreciate your enthusiasm, but you aren't going to find much down here.
There certainly aren't clues to any of the puzzles. The best surprises don't
even appear in the source until you unlock them for real.
Please be careful with automated requests; I'm not a massive company, and I can
only take so much traffic. Please be considerate so that everyone gets to play.
If you're curious about how Advent of Code works, it's running on some custom
Perl code. Other than a few integrations (auth, analytics, social media), I
built the whole thing myself, including the design, animations, prose, and all
of the puzzles.
The puzzles are most of the work; preparing a new calendar and a new set of
puzzles each year takes all of my free time for 4-5 months. A lot of effort
went into building this thing - I hope you're enjoying playing it as much as I
enjoyed making it for you!
If you'd like to hang out, I'm @ericwastl on Twitter.
- Eric Wastl
-->
<body>
<header><div><h1class="title-global"><ahref="/">Advent of Code</a></h1><nav><ul><li><ahref="/2020/about">[About]</a></li><li><ahref="/2020/events">[Events]</a></li><li><ahref="https://teespring.com/stores/advent-of-code"target="_blank">[Shop]</a></li><li><ahref="/2020/settings">[Settings]</a></li><li><ahref="/2020/auth/logout">[Log Out]</a></li></ul></nav><divclass="user">Neil Smith <ahref="/2020/support"class="supporter-badge"title="Advent of Code Supporter">(AoC++)</a><spanclass="star-count">12*</span></div></div><div><h1class="title-event"> <spanclass="title-event-wrap">var y=</span><ahref="/2020">2020</a><spanclass="title-event-wrap">;</span></h1><nav><ul><li><ahref="/2020">[Calendar]</a></li><li><ahref="/2020/support">[AoC++]</a></li><li><ahref="/2020/sponsors">[Sponsors]</a></li><li><ahref="/2020/leaderboard">[Leaderboard]</a></li><li><ahref="/2020/stats">[Stats]</a></li></ul></nav></div></header>
<divid="sidebar">
<divid="sponsor"><divclass="quiet">Our <ahref="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><divclass="sponsor"><ahref="https://jobs.americanexpress.com/technology"target="_blank"onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);"rel="noopener">American Express</a> - We architect, code and ship software that makes us an essential part of our customers’ digital lives. Work with the latest tech and back the engineering community through open source. Find your place in tech on #TeamAmex.</div></div>
<articleclass="day-desc"><h2>--- Day 5: Binary Boarding ---</h2><p>You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.</p>
<p>You write a <spantitle="No problem!">quick program</span> to use your phone's camera to scan all of the nearby boarding passes (your puzzle input); perhaps you can find your seat through process of elimination.</p>
<p>Instead of <atarget="_blank"href="https://www.youtube.com/watch?v=oAHbLRjF0vo">zones or groups</a>, this airline uses <em>binary space partitioning</em> to seat people. A seat might be specified like <code>FBFBBFFRLR</code>, where <code>F</code> means "front", <code>B</code> means "back", <code>L</code> means "left", and <code>R</code> means "right".</p>
<p>The first 7 characters will either be <code>F</code> or <code>B</code>; these specify exactly one of the <em>128 rows</em> on the plane (numbered <code>0</code> through <code>127</code>). Each letter tells you which half of a region the given seat is in. Start with the whole list of rows; the first letter indicates whether the seat is in the <em>front</em> (<code>0</code> through <code>63</code>) or the <em>back</em> (<code>64</code> through <code>127</code>). The next letter indicates which half of that region the seat is in, and so on until you're left with exactly one row.</p>
<p>For example, consider just the first seven characters of <code>FBFBBFFRLR</code>:</p>
<ul>
<li>Start by considering the whole range, rows <code>0</code> through <code>127</code>.</li>
<li><code>F</code> means to take the <em>lower half</em>, keeping rows <code>0</code> through <code>63</code>.</li>
<li><code>B</code> means to take the <em>upper half</em>, keeping rows <code>32</code> through <code>63</code>.</li>
<li><code>F</code> means to take the <em>lower half</em>, keeping rows <code>32</code> through <code>47</code>.</li>
<li><code>B</code> means to take the <em>upper half</em>, keeping rows <code>40</code> through <code>47</code>.</li>
<li><code>B</code> keeps rows <code>44</code> through <code>47</code>.</li>
<li><code>F</code> keeps rows <code>44</code> through <code>45</code>.</li>
<li>The final <code>F</code> keeps the lower of the two, <em>row <code>44</code></em>.</li>
</ul>
<p>The last three characters will be either <code>L</code> or <code>R</code>; these specify exactly one of the <em>8 columns</em> of seats on the plane (numbered <code>0</code> through <code>7</code>). The same process as above proceeds again, this time with only three steps. <code>L</code> means to keep the <em>lower half</em>, while <code>R</code> means to keep the <em>upper half</em>.</p>
<p>For example, consider just the last 3 characters of <code>FBFBBFFRLR</code>:</p>
<ul>
<li>Start by considering the whole range, columns <code>0</code> through <code>7</code>.</li>
<li><code>R</code> means to take the <em>upper half</em>, keeping columns <code>4</code> through <code>7</code>.</li>
<li><code>L</code> means to take the <em>lower half</em>, keeping columns <code>4</code> through <code>5</code>.</li>
<li>The final <code>R</code> keeps the upper of the two, <em>column <code>5</code></em>.</li>
</ul>
<p>So, decoding <code>FBFBBFFRLR</code> reveals that it is the seat at <em>row <code>44</code>, column <code>5</code></em>.</p>
<p>Every seat also has a unique <em>seat ID</em>: multiply the row by 8, then add the column. In this example, the seat has ID <code>44 * 8 + 5 = <em>357</em></code>.</p>
<p>Here are some other boarding passes:</p>
<ul>
<li><code>BFFFBBFRRR</code>: row <code>70</code>, column <code>7</code>, seat ID <code>567</code>.</li>
<li><code>FFFBBBFRRR</code>: row <code>14</code>, column <code>7</code>, seat ID <code>119</code>.</li>
<li><code>BBFFBBFRLL</code>: row <code>102</code>, column <code>4</code>, seat ID <code>820</code>.</li>
</ul>
<p>As a sanity check, look through your list of boarding passes. <em>What is the highest seat ID on a boarding pass?</em></p>
</article>
<p>Your puzzle answer was <code>922</code>.</p><articleclass="day-desc"><h2id="part2">--- Part Two ---</h2><p><em>Ding!</em> The "fasten seat belt" signs have turned on. Time to find your seat.</p>
<p>It's a completely full flight, so your seat should be the only missing boarding pass in your list. However, there's a catch: some of the seats at the very front and back of the plane don't exist on this aircraft, so they'll be missing from your list as well.</p>
<p>Your seat wasn't at the very front or back, though; the seats with IDs +1 and -1 from yours will be in your list.</p>
<p><em>What is the ID of your seat?</em></p>
</article>
<p>Your puzzle answer was <code>747</code>.</p><pclass="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
<p>At this point, you should <ahref="/2020">return to your Advent calendar</a> and try another puzzle.</p>
<p>If you still want to see it, you can <ahref="5/input"target="_blank">get your puzzle input</a>.</p>
<p>You can also <spanclass="share">[Share<spanclass="share-content">on
I appreciate your enthusiasm, but you aren't going to find much down here.
There certainly aren't clues to any of the puzzles. The best surprises don't
even appear in the source until you unlock them for real.
Please be careful with automated requests; I'm not a massive company, and I can
only take so much traffic. Please be considerate so that everyone gets to play.
If you're curious about how Advent of Code works, it's running on some custom
Perl code. Other than a few integrations (auth, analytics, social media), I
built the whole thing myself, including the design, animations, prose, and all
of the puzzles.
The puzzles are most of the work; preparing a new calendar and a new set of
puzzles each year takes all of my free time for 4-5 months. A lot of effort
went into building this thing - I hope you're enjoying playing it as much as I
enjoyed making it for you!
If you'd like to hang out, I'm @ericwastl on Twitter.
- Eric Wastl
-->
<body>
<header><div><h1class="title-global"><ahref="/">Advent of Code</a></h1><nav><ul><li><ahref="/2020/about">[About]</a></li><li><ahref="/2020/events">[Events]</a></li><li><ahref="https://teespring.com/stores/advent-of-code"target="_blank">[Shop]</a></li><li><ahref="/2020/settings">[Settings]</a></li><li><ahref="/2020/auth/logout">[Log Out]</a></li></ul></nav><divclass="user">Neil Smith <ahref="/2020/support"class="supporter-badge"title="Advent of Code Supporter">(AoC++)</a><spanclass="star-count">12*</span></div></div><div><h1class="title-event"> <spanclass="title-event-wrap">/*</span><ahref="/2020">2020</a><spanclass="title-event-wrap">*/</span></h1><nav><ul><li><ahref="/2020">[Calendar]</a></li><li><ahref="/2020/support">[AoC++]</a></li><li><ahref="/2020/sponsors">[Sponsors]</a></li><li><ahref="/2020/leaderboard">[Leaderboard]</a></li><li><ahref="/2020/stats">[Stats]</a></li></ul></nav></div></header>
<divid="sidebar">
<divid="sponsor"><divclass="quiet">Our <ahref="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><divclass="sponsor"><ahref="https://jobs.americanexpress.com/technology"target="_blank"onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);"rel="noopener">American Express</a> - We architect, code and ship software that makes us an essential part of our customers’ digital lives. Work with the latest tech and back the engineering community through open source. Find your place in tech on #TeamAmex.</div></div>
<articleclass="day-desc"><h2>--- Day 6: Custom Customs ---</h2><p>As your flight approaches the regional airport where you'll switch to a much larger plane, <ahref="https://en.wikipedia.org/wiki/Customs_declaration"target="_blank">customs declaration forms</a> are distributed to the passengers.</p>
<p>The form asks a series of 26 yes-or-no questions marked <code>a</code> through <code>z</code>. All you need to do is identify the questions for which <em>anyone in your group</em> answers "yes". Since your group is just you, this doesn't take very long.</p>
<p>However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer "yes", one per line. For example:</p>
<pre><code>abcx
abcy
abcz
</code></pre>
<p>In this group, there are <em><code>6</code></em> questions to which anyone answered "yes": <code>a</code>, <code>b</code>, <code>c</code>, <code>x</code>, <code>y</code>, and <code>z</code>. (Duplicate answers to the same question don't count extra; each question counts at most once.)</p>
<p>Another group asks for your help, then another, and eventually you've collected answers from every group on the plane (your puzzle input). Each group's answers are separated by a blank line, and within each group, each person's answers are on a single line. For example:</p>
<pre><code>abc
a
b
c
ab
ac
a
a
a
a
b
</code></pre>
<p>This list represents answers from five groups:</p>
<ul>
<li>The first group contains one person who answered "yes" to <em><code>3</code></em> questions: <code>a</code>, <code>b</code>, and <code>c</code>.</li>
<li>The second group contains three people; combined, they answered "yes" to <em><code>3</code></em> questions: <code>a</code>, <code>b</code>, and <code>c</code>.</li>
<li>The third group contains two people; combined, they answered "yes" to <em><code>3</code></em> questions: <code>a</code>, <code>b</code>, and <code>c</code>.</li>
<li>The fourth group contains four people; combined, they answered "yes" to only <em><code>1</code></em> question, <code>a</code>.</li>
<li>The last group contains one person who answered "yes" to only <em><code>1</code></em> question, <code>b</code>.</li>
</ul>
<p>In this example, the sum of these counts is <code>3 + 3 + 3 + 1 + 1</code> = <em><code>11</code></em>.</p>
<p>For each group, count the number of questions to which anyone answered "yes". <em>What is the sum of those counts?</em></p>
</article>
<p>Your puzzle answer was <code>6683</code>.</p><articleclass="day-desc"><h2id="part2">--- Part Two ---</h2><p>As you finish the last group's customs declaration, you notice that <spantitle="Don't worry, nobody ever misreads just one word in real life.">you misread one word</span> in the instructions:</p>
<p>You don't need to identify the questions to which <em>anyone</em> answered "yes"; you need to identify the questions to which <em>everyone</em> answered "yes"!</p>
<p>Using the same example as above:</p>
<pre><code>abc
a
b
c
ab
ac
a
a
a
a
b
</code></pre>
<p>This list represents answers from five groups:</p>
<ul>
<li>In the first group, everyone (all 1 person) answered "yes" to <em><code>3</code></em> questions: <code>a</code>, <code>b</code>, and <code>c</code>.</li>
<li>In the second group, there is <em>no</em> question to which everyone answered "yes".</li>
<li>In the third group, everyone answered yes to only <em><code>1</code></em> question, <code>a</code>. Since some people did not answer "yes" to <code>b</code> or <code>c</code>, they don't count.</li>
<li>In the fourth group, everyone answered yes to only <em><code>1</code></em> question, <code>a</code>.</li>
<li>In the fifth group, everyone (all 1 person) answered "yes" to <em><code>1</code></em> question, <code>b</code>.</li>
</ul>
<p>In this example, the sum of these counts is <code>3 + 0 + 1 + 1 + 1</code> = <em><code>6</code></em>.</p>
<p>For each group, count the number of questions to which <em>everyone</em> answered "yes". <em>What is the sum of those counts?</em></p>
</article>
<p>Your puzzle answer was <code>3122</code>.</p><pclass="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
<p>At this point, you should <ahref="/2020">return to your Advent calendar</a> and try another puzzle.</p>
<p>If you still want to see it, you can <ahref="6/input"target="_blank">get your puzzle input</a>.</p>
<p>You can also <spanclass="share">[Share<spanclass="share-content">on