Day 2: Part 1
This commit is contained in:
139
day2/index.html
Normal file
139
day2/index.html
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<title>Day 2 - Advent of Code 2025</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/style.css?32"/>
|
||||||
|
<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?2" 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 takes all of my free time for months every year. 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 @was.tl on Bluesky and @ericwastl@hachyderm.io
|
||||||
|
on Mastodon.
|
||||||
|
|
||||||
|
- Eric Wastl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-->
|
||||||
|
<body>
|
||||||
|
<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2025/about">[About]</a></li><li><a href="/2025/events">[Events]</a></li><li><a href="https://cottonbureau.com/people/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2025/auth/login">[Log In]</a></li></ul></nav></div><div><h1 class="title-event"> <span class="title-event-wrap">int y=</span><a href="/2025">2025</a><span class="title-event-wrap">;</span></h1><nav><ul><li><a href="/2025">[Calendar]</a></li><li><a href="/2025/support">[AoC++]</a></li><li><a href="/2025/sponsors">[Sponsors]</a></li><li><a href="/2025/leaderboard/private">[Leaderboards]</a></li><li><a href="/2025/stats">[Stats]</a></li></ul></nav></div></header>
|
||||||
|
|
||||||
|
<div id="sidebar">
|
||||||
|
<div id="sponsor"><div class="quiet">Our <a href="/2025/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="/2025/sponsors/redirect?url=https%3A%2F%2Foptiver%2Ecom%2F" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Optiver</a> - Markets never stand still, and neither do our solutions. Our engineers build and refine systems powering millions of trades a day. Finished today's challenge? Find your next one here.</div></div>
|
||||||
|
</div><!--/sidebar-->
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<article class="day-desc"><h2>--- Day 2: Gift Shop ---</h2><p>You get inside and take the elevator to its only other stop: the gift shop. "Thank you for visiting the North Pole!" gleefully exclaims a nearby sign. You aren't sure who is even allowed to visit the North Pole, but you know you can access the lobby through here, and from there you can access the rest of the North Pole base.</p>
|
||||||
|
<p>As you make your way through the <span title="They even sell lunch boxes and blue tents!">surprisingly extensive</span> selection, one of the clerks recognizes you and asks for your help.</p>
|
||||||
|
<p>As it turns out, one of the younger Elves was playing on a gift shop computer and managed to add a whole bunch of invalid product IDs to their gift shop database! Surely, it would be no trouble for you to identify the invalid product IDs for them, right?</p>
|
||||||
|
<p>They've even checked most of the product ID ranges already; they only have a few product ID ranges (your puzzle input) that you'll need to check. For example:</p>
|
||||||
|
<pre><code>11-22,95-115,998-1012,1188511880-1188511890,222220-222224,
|
||||||
|
1698522-1698528,446443-446449,38593856-38593862,565653-565659,
|
||||||
|
824824821-824824827,2121212118-2121212124</code></pre>
|
||||||
|
<p>(The ID ranges are wrapped here for legibility; in your input, they appear on a single long line.)</p>
|
||||||
|
<p>The ranges are separated by commas (<code>,</code>); each range gives its <em>first ID</em> and <em>last ID</em> separated by a dash (<code>-</code>).</p>
|
||||||
|
<p>Since the young Elf was just doing silly patterns, you can find the <em>invalid IDs</em> by looking for any ID which is made only of some sequence of digits repeated twice. So, <code>55</code> (<code>5</code> twice), <code>6464</code> (<code>64</code> twice), and <code>123123</code> (<code>123</code> twice) would all be invalid IDs.</p>
|
||||||
|
<p>None of the numbers have leading zeroes; <code>0101</code> isn't an ID at all. (<code>101</code> is a <em>valid</em> ID that you would ignore.)</p>
|
||||||
|
<p>Your job is to find all of the invalid IDs that appear in the given ranges. In the above example:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>11-22</code> has two invalid IDs, <code><em>11</em></code> and <code><em>22</em></code>.</li>
|
||||||
|
<li><code>95-115</code> has one invalid ID, <code><em>99</em></code>.</li>
|
||||||
|
<li><code>998-1012</code> has one invalid ID, <code><em>1010</em></code>.</li>
|
||||||
|
<li><code>1188511880-1188511890</code> has one invalid ID, <code><em>1188511885</em></code>.</li>
|
||||||
|
<li><code>222220-222224</code> has one invalid ID, <code><em>222222</em></code>.</li>
|
||||||
|
<li><code>1698522-1698528</code> contains no invalid IDs.</li>
|
||||||
|
<li><code>446443-446449</code> has one invalid ID, <code><em>446446</em></code>.</li>
|
||||||
|
<li><code>38593856-38593862</code> has one invalid ID, <code><em>38593859</em></code>.</li>
|
||||||
|
<li>The rest of the ranges contain no invalid IDs.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Adding up all the invalid IDs in this example produces <code><em>1227775554</em></code>.</p>
|
||||||
|
<p><em>What do you get if you add up all of the invalid IDs?</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="/2025/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>
|
||||||
1
day2/input.txt
Normal file
1
day2/input.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
385350926-385403705,48047-60838,6328350434-6328506208,638913-698668,850292-870981,656-1074,742552-796850,4457-6851,138-206,4644076-4851885,3298025-3353031,8594410816-8594543341,396-498,1558-2274,888446-916096,12101205-12154422,2323146444-2323289192,37-57,101-137,46550018-46679958,79-96,317592-341913,495310-629360,33246-46690,14711-22848,1-17,2850-4167,3723700171-3723785996,190169-242137,272559-298768,275-365,7697-11193,61-78,75373-110112,425397-451337,9796507-9899607,991845-1013464,77531934-77616074
|
||||||
20
day2/main.py
Normal file
20
day2/main.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
def is_invalid_id(n: int) -> bool:
|
||||||
|
s = str(n)
|
||||||
|
if len(s) % 2 != 0:
|
||||||
|
return False
|
||||||
|
half = len(s) // 2
|
||||||
|
return s[:half] == s[half:]
|
||||||
|
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
with open("input.txt") as f:
|
||||||
|
line = f.read().strip()
|
||||||
|
|
||||||
|
for part in line.split(","):
|
||||||
|
lo, hi = map(int, part.split("-"))
|
||||||
|
for n in range(lo, hi + 1):
|
||||||
|
if is_invalid_id(n):
|
||||||
|
total += n
|
||||||
|
|
||||||
|
print(total)
|
||||||
Reference in New Issue
Block a user