CINXE.COM
Day 3 - Advent of Code 2022
<!DOCTYPE html> <html lang="en-us"> <head> <meta charset="utf-8"/> <title>Day 3 - Advent of Code 2022</title> <link rel="stylesheet" type="text/css" href="/static/style.css?31"/> <link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?1" title="High Contrast"/> <link rel="shortcut icon" href="/favicon.png"/> <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> </head><!-- Oh, hello! Funny seeing you here. 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@hachyderm.io on Mastodon and @ericwastl on Twitter. - Eric Wastl --> <body> <header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2022/about">[About]</a></li><li><a href="/2022/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2022/auth/login">[Log In]</a></li></ul></nav></div><div><h1 class="title-event"> <span class="title-event-wrap">位y.</span><a href="/2022">2022</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2022">[Calendar]</a></li><li><a href="/2022/support">[AoC++]</a></li><li><a href="/2022/sponsors">[Sponsors]</a></li><li><a href="/2022/leaderboard">[Leaderboard]</a></li><li><a href="/2022/stats">[Stats]</a></li></ul></nav></div></header> <div id="sidebar"> <div id="sponsor"><div class="quiet">Our <a href="/2022/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.mistplay.com" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Mistplay</a> - The #1 loyalty platform for mobile gamers! Looking for engineers!</div></div> </div><!--/sidebar--> <main> <article class="day-desc"><h2>--- Day 3: Rucksack Reorganization ---</h2><p>One Elf has the important job of loading all of the <a href="https://en.wikipedia.org/wiki/Rucksack" target="_blank">rucksacks</a> with supplies for the <span title="Where there's jungle, there's hijinxs.">jungle</span> journey. Unfortunately, that Elf didn't quite follow the packing instructions, and so a few items now need to be rearranged.</p> <p>Each rucksack has two large <em>compartments</em>. All items of a given type are meant to go into exactly one of the two compartments. The Elf that did the packing failed to follow this rule for exactly one item type per rucksack.</p> <p>The Elves have made a list of all of the items currently in each rucksack (your puzzle input), but they need your help finding the errors. Every item type is identified by a single lowercase or uppercase letter (that is, <code>a</code> and <code>A</code> refer to different types of items).</p> <p>The list of items for each rucksack is given as characters all on a single line. A given rucksack always has the same number of items in each of its two compartments, so the first half of the characters represent items in the first compartment, while the second half of the characters represent items in the second compartment.</p> <p>For example, suppose you have the following list of contents from six rucksacks:</p> <pre><code>vJrwpWtwJgWrhcsFMMfFFhFp jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL PmmdzqPrVvPwwTWBwg wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn ttgJtRGJQctTZtZT CrZsJsPPZsGzwwsLwLmpwMDw </code></pre> <ul> <li>The first rucksack contains the items <code>vJrwpWtwJgWrhcsFMMfFFhFp</code>, which means its first compartment contains the items <code>vJrwpWtwJgWr</code>, while the second compartment contains the items <code>hcsFMMfFFhFp</code>. The only item type that appears in both compartments is lowercase <code><em>p</em></code>.</li> <li>The second rucksack's compartments contain <code>jqHRNqRjqzjGDLGL</code> and <code>rsFMfFZSrLrFZsSL</code>. The only item type that appears in both compartments is uppercase <code><em>L</em></code>.</li> <li>The third rucksack's compartments contain <code>PmmdzqPrV</code> and <code>vPwwTWBwg</code>; the only common item type is uppercase <code><em>P</em></code>.</li> <li>The fourth rucksack's compartments only share item type <code><em>v</em></code>.</li> <li>The fifth rucksack's compartments only share item type <code><em>t</em></code>.</li> <li>The sixth rucksack's compartments only share item type <code><em>s</em></code>.</li> </ul> <p>To help prioritize item rearrangement, every item type can be converted to a <em>priority</em>:</p> <ul> <li>Lowercase item types <code>a</code> through <code>z</code> have priorities 1 through 26.</li> <li>Uppercase item types <code>A</code> through <code>Z</code> have priorities 27 through 52.</li> </ul> <p>In the above example, the priority of the item type that appears in both compartments of each rucksack is 16 (<code>p</code>), 38 (<code>L</code>), 42 (<code>P</code>), 22 (<code>v</code>), 20 (<code>t</code>), and 19 (<code>s</code>); the sum of these is <code><em>157</em></code>.</p> <p>Find the item type that appears in both compartments of each rucksack. <em>What is the sum of the priorities of those item types?</em></p> </article> <p>To play, please identify yourself via one of these services:</p> <p><a href="/auth/github">[GitHub]</a> <a href="/auth/google">[Google]</a> <a href="/auth/twitter">[Twitter]</a> <a href="/auth/reddit">[Reddit]</a> <span class="quiet">- <a href="/about#faq_auth">[How Does Auth Work?]</a></span></p> </main> <!-- ga --> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-69522494-1', 'auto'); ga('set', 'anonymizeIp', true); ga('send', 'pageview'); </script> <!-- /ga --> </body> </html>