4 <meta charset=
"utf-8"/>
5 <title>Day
4 - 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">8*
</span></div></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>
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.bjss.com/" target=
"_blank" onclick=
"if(ga)ga('send','event','sponsor','sidebar',this.href);" rel=
"noopener">BJSS
</a> - Our people are a team of problem solvers, experienced in evolving technologies and delivering world-class technology solutions.
</div></div>
98 <article class=
"day-desc"><h2>--- Day
4: Camp Cleanup ---
</h2><p>Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been assigned the job of cleaning up sections of the camp. Every section has a unique
<em>ID number
</em>, and each Elf is assigned a range of section IDs.
</p>
99 <p>However, as some of the Elves compare their section assignments with each other, they've noticed that many of the assignments
<em>overlap
</em>. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a
<em>big list of the section assignments for each pair
</em> (your puzzle input).
</p>
100 <p>For example, consider the following list of section assignment pairs:
</p>
108 <p>For the first few pairs, this list means:
</p>
110 <li>Within the first pair of Elves, the first Elf was assigned sections
<code>2-
4</code> (sections
<code>2</code>,
<code>3</code>, and
<code>4</code>), while the second Elf was assigned sections
<code>6-
8</code> (sections
<code>6</code>,
<code>7</code>,
<code>8</code>).
</li>
111 <li>The Elves in the second pair were each assigned two sections.
</li>
112 <li>The Elves in the third pair were each assigned three sections: one got sections
<code>5</code>,
<code>6</code>, and
<code>7</code>, while the other also got
<code>7</code>, plus
<code>8</code> and
<code>9</code>.
</li>
114 <p>This example list uses single-digit section IDs to make it easier to draw; your actual list might contain larger numbers. Visually, these pairs of section assignments look like this:
</p>
115 <pre><code>.234.....
2-
4
133 <p>Some of the pairs have noticed that one of their assignments
<em>fully contains
</em> the other. For example,
<code>2-
8</code> fully contains
<code>3-
7</code>, and
<code>6-
6</code> is fully contained by
<code>4-
6</code>. In pairs where one assignment fully contains the other, one Elf in the pair would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of reconsideration. In this example, there are
<code><em>2</em></code> such pairs.
</p>
134 <p><em>In how many assignment pairs does one range fully contain the other?
</em></p>
136 <p>Your puzzle answer was
<code>513</code>.
</p><article class=
"day-desc"><h2 id=
"part2">--- Part Two ---
</h2><p>It seems like there is still quite a bit of duplicate work planned. Instead, the Elves would
<span title=
"If you like this, you'll *love* axis-aligned bounding box intersection testing.">like
</span> to know the number of pairs that
<em>overlap at all
</em>.
</p>
137 <p>In the above example, the first two pairs (
<code>2-
4,
6-
8</code> and
<code>2-
3,
4-
5</code>) don't overlap, while the remaining four pairs (
<code>5-
7,
7-
9</code>,
<code>2-
8,
3-
7</code>,
<code>6-
6,
4-
6</code>, and
<code>2-
6,
4-
8</code>) do overlap:
</p>
139 <li><code>5-
7,
7-
9</code> overlaps in a single section,
<code>7</code>.
</li>
140 <li><code>2-
8,
3-
7</code> overlaps all of the sections
<code>3</code> through
<code>7</code>.
</li>
141 <li><code>6-
6,
4-
6</code> overlaps in a single section,
<code>6</code>.
</li>
142 <li><code>2-
6,
4-
8</code> overlaps in sections
<code>4</code>,
<code>5</code>, and
<code>6</code>.
</li>
144 <p>So, in this example, the number of overlapping assignment pairs is
<code><em>4</em></code>.
</p>
145 <p><em>In how many assignment pairs do the ranges overlap?
</em></p>
147 <p>Your puzzle answer was
<code>878</code>.
</p><p class=
"day-success">Both parts of this puzzle are complete! They provide two gold stars: **
</p>
148 <p>At this point, you should
<a href=
"/2022">return to your Advent calendar
</a> and try another puzzle.
</p>
149 <p>If you still want to see it, you can
<a href=
"4/input" target=
"_blank">get your puzzle input
</a>.
</p>
150 <p>You can also
<span class=
"share">[Share
<span class=
"share-content">on
151 <a href=
"https://twitter.com/intent/tweet?text=I%27ve+completed+%22Camp+Cleanup%22+%2D+Day+4+%2D+Advent+of+Code+2022&url=https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F4&related=ericwastl&hashtags=AdventOfCode" target=
"_blank">Twitter
</a>
152 <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+%22Camp+Cleanup%22+%2D+Day+4+%2D+Advent+of+Code+2022+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2022%2Fday%2F4'}else{return false;}" target=
"_blank">Mastodon
</a
153 ></span>]
</span> this puzzle.
</p>
158 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
159 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=
1*new Date();a=s.createElement(o),
160 m=s.getElementsByTagName(o)[
0];a.async=
1;a.src=g;m.parentNode.insertBefore(a,m)
161 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
162 ga('create', 'UA-
69522494-
1', 'auto');
163 ga('set', 'anonymizeIp', true);
164 ga('send', 'pageview');