4 <meta charset=
"utf-8"/>
5 <title>Day
3 - Advent of Code
2022</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?30"/>
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 <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>
17 Oh, hello! Funny seeing you here.
19 I appreciate your enthusiasm, but you aren't going to find much down here.
20 There certainly aren't clues to any of the puzzles. The best surprises don't
21 even appear in the source until you unlock them for real.
23 Please be careful with automated requests; I'm not a massive company, and I can
24 only take so much traffic. Please be considerate so that everyone gets to play.
26 If you're curious about how Advent of Code works, it's running on some custom
27 Perl code. Other than a few integrations (auth, analytics, social media), I
28 built the whole thing myself, including the design, animations, prose, and all
31 The puzzles are most of the work; preparing a new calendar and a new set of
32 puzzles each year takes all of my free time for 4-5 months. A lot of effort
33 went into building this thing - I hope you're enjoying playing it as much as I
34 enjoyed making it for you!
36 If you'd like to hang out, I'm @ericwastl on Twitter.
91 <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/settings">[Settings]
</a></li><li><a href=
"/2022/auth/logout">[Log Out]
</a></li></ul></nav><div class=
"user">Neil Smith
<a href=
"/2022/support" class=
"supporter-badge" title=
"Advent of Code Supporter">(AoC++)
</a> <span class=
"star-count">6*
</span></div></div><div><h1 class=
"title-event"> <span class=
"title-event-wrap">$year=
</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>
94 <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.retool.com" target=
"_blank" onclick=
"if(ga)ga('send','event','sponsor','sidebar',this.href);" rel=
"noopener">Retool
</a> - Quickly build CRUD apps, admin panels, recurring jobs, and dashboards with JavaScript. Run in our cloud or yours. Free for small teams.
</div></div>
98 <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>
99 <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>
100 <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>
101 <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>
102 <p>For example, suppose you have the following list of contents from six rucksacks:
</p>
103 <pre><code>vJrwpWtwJgWrhcsFMMfFFhFp
104 jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
106 wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
108 CrZsJsPPZsGzwwsLwLmpwMDw
111 <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>
112 <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>
113 <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>
114 <li>The fourth rucksack's compartments only share item type
<code><em>v
</em></code>.
</li>
115 <li>The fifth rucksack's compartments only share item type
<code><em>t
</em></code>.
</li>
116 <li>The sixth rucksack's compartments only share item type
<code><em>s
</em></code>.
</li>
118 <p>To help prioritize item rearrangement, every item type can be converted to a
<em>priority
</em>:
</p>
120 <li>Lowercase item types
<code>a
</code> through
<code>z
</code> have priorities
1 through
26.
</li>
121 <li>Uppercase item types
<code>A
</code> through
<code>Z
</code> have priorities
27 through
52.
</li>
123 <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>
124 <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>
126 <p>Your puzzle answer was
<code>7727</code>.
</p><article class=
"day-desc"><h2 id=
"part2">--- Part Two ---
</h2><p>As you finish identifying the misplaced items, the Elves come to you with another issue.
</p>
127 <p>For safety, the Elves are divided into groups of three. Every Elf carries a badge that identifies their group. For efficiency, within each group of three Elves, the badge is the
<em>only item type carried by all three Elves
</em>. That is, if a group's badge is item type
<code>B
</code>, then all three Elves will have item type
<code>B
</code> somewhere in their rucksack, and at most two of the Elves will be carrying any other item type.
</p>
128 <p>The problem is that someone forgot to put this year's updated authenticity sticker on the badges. All of the badges need to be pulled out of the rucksacks so the new authenticity stickers can be attached.
</p>
129 <p>Additionally, nobody wrote down which item type corresponds to each group's badges. The only way to tell which item type is the right one is by finding the one item type that is
<em>common between all three Elves
</em> in each group.
</p>
130 <p>Every set of three lines in your list corresponds to a single group, but each group can have a different badge item type. So, in the above example, the first group's rucksacks are the first three lines:
</p>
131 <pre><code>vJrwpWtwJgWrhcsFMMfFFhFp
132 jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
135 <p>And the second group's rucksacks are the next three lines:
</p>
136 <pre><code>wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
138 CrZsJsPPZsGzwwsLwLmpwMDw
140 <p>In the first group, the only item type that appears in all three rucksacks is lowercase
<code>r
</code>; this must be their badges. In the second group, their badge item type must be
<code>Z
</code>.
</p>
141 <p>Priorities for these items must still be found to organize the sticker attachment efforts: here, they are
18 (
<code>r
</code>) for the first group and
52 (
<code>Z
</code>) for the second group. The sum of these is
<code><em>70</em></code>.
</p>
142 <p>Find the item type that corresponds to the badges of each three-Elf group.
<em>What is the sum of the priorities of those item types?
</em></p>
144 <p>Your puzzle answer was
<code>2609</code>.
</p><p class=
"day-success">Both parts of this puzzle are complete! They provide two gold stars: **
</p>
145 <p>At this point, you should
<a href=
"/2022">return to your Advent calendar
</a> and try another puzzle.
</p>
146 <p>If you still want to see it, you can
<a href=
"3/input" target=
"_blank">get your puzzle input
</a>.
</p>
147 <p>You can also
<span class=
"share">[Share
<span class=
"share-content">on
148 <a href=
"https://twitter.com/intent/tweet?text=I%27ve+completed+%22Rucksack+Reorganization%22+%2D+Day+3+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F3&related=ericwastl&hashtags=AdventOfCode" target=
"_blank">Twitter
</a>
149 <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+%22Rucksack+Reorganization%22+%2D+Day+3+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F3'}else{return false;}" target=
"_blank">Mastodon
</a
150 ></span>]
</span> this puzzle.
</p>
155 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
156 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=
1*new Date();a=s.createElement(o),
157 m=s.getElementsByTagName(o)[
0];a.async=
1;a.src=g;m.parentNode.insertBefore(a,m)
158 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
159 ga('create', 'UA-
69522494-
1', 'auto');
160 ga('set', 'anonymizeIp', true);
161 ga('send', 'pageview');