day08/09
This commit is contained in:
628
day08/data/data.txt
Normal file
628
day08/data/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
184
day08/index.html
Normal file
184
day08/index.html
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<title>Day 8 - Advent of Code 2020</title>
|
||||||
|
<!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
|
||||||
|
<link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/style.css?25"/>
|
||||||
|
<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
|
||||||
|
<link rel="shortcut icon" href="/favicon.png"/>
|
||||||
|
</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 on Twitter.
|
||||||
|
|
||||||
|
- Eric Wastl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-->
|
||||||
|
<body>
|
||||||
|
<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2020/about">[About]</a></li><li><a href="/2020/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2020/settings">[Settings]</a></li><li><a href="/2020/auth/logout">[Log Out]</a></li></ul></nav><div class="user">m42e <a href="/2020/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">16*</span></div></div><div><h1 class="title-event"> <span class="title-event-wrap">int y=</span><a href="/2020">2020</a><span class="title-event-wrap">;</span></h1><nav><ul><li><a href="/2020">[Calendar]</a></li><li><a href="/2020/support">[AoC++]</a></li><li><a href="/2020/sponsors">[Sponsors]</a></li><li><a href="/2020/leaderboard">[Leaderboard]</a></li><li><a href="/2020/stats">[Stats]</a></li></ul></nav></div></header>
|
||||||
|
|
||||||
|
<div id="sidebar">
|
||||||
|
<div id="sponsor"><div class="quiet">Our <a href="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://tretton37.com/join" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">tretton37</a> - Means 1337 in Swedish. What you see is who we are!</div></div>
|
||||||
|
</div><!--/sidebar-->
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<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>
|
||||||
|
<article class="day-desc"><h2>--- Day 8: Handheld Halting ---</h2><p>Your flight to the major airline hub reaches cruising altitude without incident. While you consider checking the in-flight menu for one of those drinks that come with a little umbrella, you are interrupted by the kid sitting next to you.</p>
|
||||||
|
<p>Their <a target="_blank" href="https://en.wikipedia.org/wiki/Handheld_game_console">handheld game console</a> won't turn on! They ask if you can take a look.</p>
|
||||||
|
<p>You narrow the problem down to a strange <em>infinite loop</em> in the <span title="A trendy new line of encrypted footwear?">boot code</span> (your puzzle input) of the device. You should be able to fix it, but first you need to be able to run the code in isolation.</p>
|
||||||
|
<p>The boot code is represented as a text file with one <em>instruction</em> per line of text. Each instruction consists of an <em>operation</em> (<code>acc</code>, <code>jmp</code>, or <code>nop</code>) and an <em>argument</em> (a signed number like <code>+4</code> or <code>-20</code>).</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>acc</code> increases or decreases a single global value called the <em>accumulator</em> by the value given in the argument. For example, <code>acc +7</code> would increase the accumulator by 7. The accumulator starts at <code>0</code>. After an <code>acc</code> instruction, the instruction immediately below it is executed next.</li>
|
||||||
|
<li><code>jmp</code> <em>jumps</em> to a new instruction relative to itself. The next instruction to execute is found using the argument as an <em>offset</em> from the <code>jmp</code> instruction; for example, <code>jmp +2</code> would skip the next instruction, <code>jmp +1</code> would continue to the instruction immediately below it, and <code>jmp -20</code> would cause the instruction 20 lines above to be executed next.</li>
|
||||||
|
<li><code>nop</code> stands for <em>No OPeration</em> - it does nothing. The instruction immediately below it is executed next.</li>
|
||||||
|
</ul>
|
||||||
|
<p>For example, consider the following program:</p>
|
||||||
|
<pre><code>nop +0
|
||||||
|
acc +1
|
||||||
|
jmp +4
|
||||||
|
acc +3
|
||||||
|
jmp -3
|
||||||
|
acc -99
|
||||||
|
acc +1
|
||||||
|
jmp -4
|
||||||
|
acc +6
|
||||||
|
</code></pre>
|
||||||
|
<p>These instructions are visited in this order:</p>
|
||||||
|
<pre><code>nop +0 | 1
|
||||||
|
acc +1 | 2, 8(!)
|
||||||
|
jmp +4 | 3
|
||||||
|
acc +3 | 6
|
||||||
|
jmp -3 | 7
|
||||||
|
acc -99 |
|
||||||
|
acc +1 | 4
|
||||||
|
jmp -4 | 5
|
||||||
|
acc +6 |
|
||||||
|
</code></pre>
|
||||||
|
<p>First, the <code>nop +0</code> does nothing. Then, the accumulator is increased from 0 to 1 (<code>acc +1</code>) and <code>jmp +4</code> sets the next instruction to the other <code>acc +1</code> near the bottom. After it increases the accumulator from 1 to 2, <code>jmp -4</code> executes, setting the next instruction to the only <code>acc +3</code>. It sets the accumulator to 5, and <code>jmp -3</code> causes the program to continue back at the first <code>acc +1</code>.</p>
|
||||||
|
<p>This is an <em>infinite loop</em>: with this sequence of jumps, the program will run forever. The moment the program tries to run any instruction a second time, you know it will never terminate.</p>
|
||||||
|
<p>Immediately <em>before</em> the program would run an instruction a second time, the value in the accumulator is <em><code>5</code></em>.</p>
|
||||||
|
<p>Run your copy of the boot code. Immediately before any instruction is executed a second time, <em>what value is in the accumulator?</em></p>
|
||||||
|
</article>
|
||||||
|
<p>Your puzzle answer was <code>1766</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>After some careful analysis, you believe that <em>exactly one instruction is corrupted</em>.</p>
|
||||||
|
<p>Somewhere in the program, <em>either</em> a <code>jmp</code> is supposed to be a <code>nop</code>, <em>or</em> a <code>nop</code> is supposed to be a <code>jmp</code>. (No <code>acc</code> instructions were harmed in the corruption of this boot code.)</p>
|
||||||
|
<p>The program is supposed to terminate by <em>attempting to execute an instruction immediately after the last instruction in the file</em>. By changing exactly one <code>jmp</code> or <code>nop</code>, you can repair the boot code and make it terminate correctly.</p>
|
||||||
|
<p>For example, consider the same program from above:</p>
|
||||||
|
<pre><code>nop +0
|
||||||
|
acc +1
|
||||||
|
jmp +4
|
||||||
|
acc +3
|
||||||
|
jmp -3
|
||||||
|
acc -99
|
||||||
|
acc +1
|
||||||
|
jmp -4
|
||||||
|
acc +6
|
||||||
|
</code></pre>
|
||||||
|
<p>If you change the first instruction from <code>nop +0</code> to <code>jmp +0</code>, it would create a single-instruction infinite loop, never leaving that instruction. If you change almost any of the <code>jmp</code> instructions, the program will still eventually find another <code>jmp</code> instruction and loop forever.</p>
|
||||||
|
<p>However, if you change the second-to-last instruction (from <code>jmp -4</code> to <code>nop -4</code>), the program terminates! The instructions are visited in this order:</p>
|
||||||
|
<pre><code>nop +0 | 1
|
||||||
|
acc +1 | 2
|
||||||
|
jmp +4 | 3
|
||||||
|
acc +3 |
|
||||||
|
jmp -3 |
|
||||||
|
acc -99 |
|
||||||
|
acc +1 | 4
|
||||||
|
<em>nop</em> -4 | 5
|
||||||
|
acc +6 | 6
|
||||||
|
</code></pre>
|
||||||
|
<p>After the last instruction (<code>acc +6</code>), the program terminates by attempting to run the instruction below the last instruction in the file. With this change, after the program terminates, the accumulator contains the value <em><code>8</code></em> (<code>acc +1</code>, <code>acc +1</code>, <code>acc +6</code>).</p>
|
||||||
|
<p>Fix the program so that it terminates normally by changing exactly one <code>jmp</code> (to <code>nop</code>) or <code>nop</code> (to <code>jmp</code>). <em>What is the value of the accumulator after the program terminates?</em></p>
|
||||||
|
</article>
|
||||||
|
<p>Your puzzle answer was <code>1639</code>.</p><p class="day-success">Both parts of this puzzle are complete! They provide two gold stars: **</p>
|
||||||
|
<p>At this point, you should <a href="/2020">return to your Advent calendar</a> and try another puzzle.</p>
|
||||||
|
<p>If you still want to see it, you can <a href="8/input" target="_blank">get your puzzle input</a>.</p>
|
||||||
|
<p>You can also <span class="share">[Share<span class="share-content">on
|
||||||
|
<a href="https://twitter.com/intent/tweet?text=I%27ve+completed+%22Handheld+Halting%22+%2D+Day+8+%2D+Advent+of+Code+2020&url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F8&related=ericwastl&hashtags=AdventOfCode" target="_blank">Twitter</a>
|
||||||
|
<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+%22Handheld+Halting%22+%2D+Day+8+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F8'}else{return false;}" target="_blank">Mastodon</a
|
||||||
|
></span>]</span> this puzzle.</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>
|
||||||
1000
day09/data/data.txt
Normal file
1000
day09/data/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
20
day09/data/sample.txt
Normal file
20
day09/data/sample.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
35
|
||||||
|
20
|
||||||
|
15
|
||||||
|
25
|
||||||
|
47
|
||||||
|
40
|
||||||
|
62
|
||||||
|
55
|
||||||
|
65
|
||||||
|
95
|
||||||
|
102
|
||||||
|
117
|
||||||
|
150
|
||||||
|
182
|
||||||
|
127
|
||||||
|
219
|
||||||
|
299
|
||||||
|
277
|
||||||
|
309
|
||||||
|
576
|
||||||
160
day09/index.html
Normal file
160
day09/index.html
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<title>Day 9 - Advent of Code 2020</title>
|
||||||
|
<!--[if lt IE 9]><script src="/static/html5.js"></script><![endif]-->
|
||||||
|
<link href='//fonts.googleapis.com/css?family=Source+Code+Pro:300&subset=latin,latin-ext' rel='stylesheet' type='text/css'/>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/static/style.css?25"/>
|
||||||
|
<link rel="stylesheet alternate" type="text/css" href="/static/highcontrast.css?0" title="High Contrast"/>
|
||||||
|
<link rel="shortcut icon" href="/favicon.png"/>
|
||||||
|
</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 on Twitter.
|
||||||
|
|
||||||
|
- Eric Wastl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-->
|
||||||
|
<body>
|
||||||
|
<header><div><h1 class="title-global"><a href="/">Advent of Code</a></h1><nav><ul><li><a href="/2020/about">[About]</a></li><li><a href="/2020/events">[Events]</a></li><li><a href="https://teespring.com/stores/advent-of-code" target="_blank">[Shop]</a></li><li><a href="/2020/settings">[Settings]</a></li><li><a href="/2020/auth/logout">[Log Out]</a></li></ul></nav><div class="user">m42e <a href="/2020/support" class="supporter-badge" title="Advent of Code Supporter">(AoC++)</a> <span class="star-count">16*</span></div></div><div><h1 class="title-event"> <span class="title-event-wrap">0x0000|</span><a href="/2020">2020</a><span class="title-event-wrap"></span></h1><nav><ul><li><a href="/2020">[Calendar]</a></li><li><a href="/2020/support">[AoC++]</a></li><li><a href="/2020/sponsors">[Sponsors]</a></li><li><a href="/2020/leaderboard">[Leaderboard]</a></li><li><a href="/2020/stats">[Stats]</a></li></ul></nav></div></header>
|
||||||
|
|
||||||
|
<div id="sidebar">
|
||||||
|
<div id="sponsor"><div class="quiet">Our <a href="/2020/sponsors">sponsors</a> help make Advent of Code possible:</div><div class="sponsor"><a href="https://www.educative.io/adventofcode" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Educative.io</a> - From CSS to System Design, gain in-demand tech skills at the speed you want. Text-based courses with live coding environments help you learn without the fluff</div></div>
|
||||||
|
</div><!--/sidebar-->
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<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>
|
||||||
|
<article class="day-desc"><h2>--- Day 9: Encoding Error ---</h2><p>With your neighbor happily enjoying their video game, you turn your attention to an open data port on the little screen in the seat in front of you.</p>
|
||||||
|
<p>Though the port is non-standard, you manage to connect it to your computer through the clever use of several paperclips. Upon connection, the port outputs a series of numbers (your puzzle input).</p>
|
||||||
|
<p>The data appears to be encrypted with the eXchange-Masking Addition System (<span title="No relation.">XMAS</span>) which, conveniently for you, is an old cypher with an important weakness.</p>
|
||||||
|
<p>XMAS starts by transmitting a <em>preamble</em> of 25 numbers. After that, each number you receive should be the sum of any two of the 25 immediately previous numbers. The two numbers will have different values, and there might be more than one such pair.</p>
|
||||||
|
<p>For example, suppose your preamble consists of the numbers <code>1</code> through <code>25</code> in a random order. To be valid, the next number must be the sum of two of those numbers:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>26</code> would be a <em>valid</em> next number, as it could be <code>1</code> plus <code>25</code> (or many other pairs, like <code>2</code> and <code>24</code>).</li>
|
||||||
|
<li><code>49</code> would be a <em>valid</em> next number, as it is the sum of <code>24</code> and <code>25</code>.</li>
|
||||||
|
<li><code>100</code> would <em>not</em> be valid; no two of the previous 25 numbers sum to <code>100</code>.</li>
|
||||||
|
<li><code>50</code> would also <em>not</em> be valid; although <code>25</code> appears in the previous 25 numbers, the two numbers in the pair must be different.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Suppose the 26th number is <code>45</code>, and the first number (no longer an option, as it is more than 25 numbers ago) was <code>20</code>. Now, for the next number to be valid, there needs to be some pair of numbers among <code>1</code>-<code>19</code>, <code>21</code>-<code>25</code>, or <code>45</code> that add up to it:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>26</code> would still be a <em>valid</em> next number, as <code>1</code> and <code>25</code> are still within the previous 25 numbers.</li>
|
||||||
|
<li><code>65</code> would <em>not</em> be valid, as no two of the available numbers sum to it.</li>
|
||||||
|
<li><code>64</code> and <code>66</code> would both be <em>valid</em>, as they are the result of <code>19+45</code> and <code>21+45</code> respectively.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Here is a larger example which only considers the previous <em>5</em> numbers (and has a preamble of length 5):</p>
|
||||||
|
<pre><code>35
|
||||||
|
20
|
||||||
|
15
|
||||||
|
25
|
||||||
|
47
|
||||||
|
40
|
||||||
|
62
|
||||||
|
55
|
||||||
|
65
|
||||||
|
95
|
||||||
|
102
|
||||||
|
117
|
||||||
|
150
|
||||||
|
182
|
||||||
|
127
|
||||||
|
219
|
||||||
|
299
|
||||||
|
277
|
||||||
|
309
|
||||||
|
576
|
||||||
|
</code></pre>
|
||||||
|
<p>In this example, after the 5-number preamble, almost every number is the sum of two of the previous 5 numbers; the only number that does not follow this rule is <em><code>127</code></em>.</p>
|
||||||
|
<p>The first step of attacking the weakness in the XMAS data is to find the first number in the list (after the preamble) which is <em>not</em> the sum of two of the 25 numbers before it. <em>What is the first number that does not have this property?</em></p>
|
||||||
|
</article>
|
||||||
|
<p>To begin, <a href="9/input" target="_blank">get your puzzle input</a>.</p>
|
||||||
|
<form method="post" action="9/answer"><input type="hidden" name="level" value="1"/><p>Answer: <input type="text" name="answer" autocomplete="off"/> <input type="submit" value="[Submit]"/></p></form>
|
||||||
|
<p>You can also <span class="share">[Share<span class="share-content">on
|
||||||
|
<a href="https://twitter.com/intent/tweet?text=%22Encoding+Error%22+%2D+Day+9+%2D+Advent+of+Code+2020&url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F9&related=ericwastl&hashtags=AdventOfCode" target="_blank">Twitter</a>
|
||||||
|
<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=%22Encoding+Error%22+%2D+Day+9+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F9'}else{return false;}" target="_blank">Mastodon</a
|
||||||
|
></span>]</span> this puzzle.</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>
|
||||||
53
day09/module.py
Normal file
53
day09/module.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
from aoc.input import get_input
|
||||||
|
import copy
|
||||||
|
import itertools
|
||||||
|
import time
|
||||||
|
import collections
|
||||||
|
import re
|
||||||
|
from aoc.partselector import part_one, part_two
|
||||||
|
import functools
|
||||||
|
|
||||||
|
def pw(line):
|
||||||
|
return int(line.strip())
|
||||||
|
|
||||||
|
def p1():
|
||||||
|
inp = get_input(pw)
|
||||||
|
for i in range(25, len(inp)):
|
||||||
|
possible_values = set()
|
||||||
|
for sample in itertools.combinations(inp[i-25:i], 2):
|
||||||
|
possible_values.add(sum(sample))
|
||||||
|
if inp[i] not in possible_values:
|
||||||
|
print (inp[i])
|
||||||
|
return inp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return inp
|
||||||
|
|
||||||
|
|
||||||
|
def p2(inp):
|
||||||
|
l = 1398413738
|
||||||
|
i = 636
|
||||||
|
d = {}
|
||||||
|
for j in range(2, 25):
|
||||||
|
possible_values = set()
|
||||||
|
for sample in range(1,636):
|
||||||
|
possible_values.add(sum(inp[sample: sample+j]))
|
||||||
|
d [sum(inp[sample: sample+j])] = inp[sample: sample+j]
|
||||||
|
if l in possible_values:
|
||||||
|
print(min(d[l]) + max(d[l]))
|
||||||
|
return (min(d[l]) + max(d[l]))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if part_one():
|
||||||
|
start = time.time()
|
||||||
|
result1 = p1()
|
||||||
|
print(round(1000*(time.time() - start), 2), 'ms')
|
||||||
|
|
||||||
|
|
||||||
|
if part_two():
|
||||||
|
start = time.time()
|
||||||
|
p2(result1)
|
||||||
|
print(round(1000*(time.time() - start), 2), 'ms')
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user