Compare commits

...

18 Commits

Author SHA1 Message Date
e0b88a05b4 help 2020-12-24 07:13:42 +01:00
52623631c7 frozen set 2020-12-22 07:14:57 +01:00
413a8b50f2 day22 2020-12-22 07:08:57 +01:00
338ee35832 fixed p2 2020-12-21 07:15:28 +01:00
e5008e67a1 day21 2020-12-21 07:11:54 +01:00
1ab4862804 fixed p1 2020-12-18 09:41:08 +01:00
e1df2a6d5a updated open script 2020-12-18 09:21:16 +01:00
0af6bb9594 days 15-18 (be careful, crap 2020-12-18 09:20:55 +01:00
1b26f45c1f day14 2020-12-14 06:24:28 +01:00
bb0dca165d open improved 2020-12-13 07:16:50 +01:00
5792262ecf day 13 2020-12-13 07:16:35 +01:00
482ef7dfe3 day 12 2020-12-12 06:31:38 +01:00
3a96aff0a3 use 2d array 2020-12-11 08:15:36 +01:00
c882ea9278 day 11 2020-12-11 08:09:46 +01:00
11733b6d15 day10 2020-12-10 07:45:46 +01:00
d552142019 day08/09 2020-12-09 21:58:36 +01:00
dc12f63058 day08 2020-12-08 06:46:39 +01:00
42876de159 updated 2020-12-07 18:29:00 +01:00
65 changed files with 7520 additions and 5 deletions

View File

@@ -17,14 +17,14 @@ def p1():
for element in sample[1:]: for element in sample[1:]:
if 'no' in element: if 'no' in element:
continue continue
data.append(element.split(' ', 1)) data.append(tuple(element.split(' ', 1)))
pwd[sample[0]] = data pwd[sample[0]] = data
@functools.lru_cache(maxsize=256) @functools.lru_cache(maxsize=256)
def contains_gold(y): def contains_gold(y):
return 'shiny gold' == y or any(map(lambda x: contains_gold(x[1]), pwd[y])) return 'shiny gold' == y or any(map(lambda x: contains_gold(x[1]), pwd[y]))
s = sum(map(lambda x: any(map(lambda x: contains_gold(x[1]), pwd[x])), pwd)) s = sum(map(lambda x: any(map(lambda y: contains_gold(y[1]), pwd[x])), pwd))
print(s) print(s)
@@ -53,12 +53,12 @@ def p2(r):
if part_one(): if part_one():
start = time.time() start = time.time()
result1 = p1() result1 = p1()
print(round(time.time() - start, 6), 's') print(round(1000*(time.time() - start), 2), 'ms')
if part_two(): if part_two():
start = time.time() start = time.time()
p2(result1) p2(result1)
print(round(time.time() - start, 6), 's') print(round(1000*(time.time() - start), 2), 'ms')

628
day08/data/data.txt Normal file

File diff suppressed because it is too large Load Diff

184
day08/index.html Normal file
View 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">&nbsp;&nbsp;&nbsp;<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&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F8&amp;related=ericwastl&amp;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>

95
day08/module.py Normal file
View File

@@ -0,0 +1,95 @@
from aoc.input import get_input
import copy
import time
import collections
import re
from aoc.partselector import part_one, part_two
import functools
def pw(line):
return line.strip().split(' ')
def p1():
inp = get_input(pw)
visited = set()
current = 0
value = 0
while current not in visited:
visited.add(current)
if inp[current][0] == 'nop':
current += 1
continue
if inp[current][0] == 'jmp':
if inp[current][1][0] == '+':
current += int(inp[current][1][1:])
else:
current -= int(inp[current][1][1:])
continue
if inp[current][0] == 'acc':
if inp[current][1][0] == '+':
value += int(inp[current][1][1:])
else:
value -= int(inp[current][1][1:])
current += 1
continue
print(current)
print(value)
return inp
def p2(inp):
inp.append(['end', '0'])
orig = copy.deepcopy(inp)
for nopcount in range(0, len(inp)):
if inp[nopcount][0] not in ['nop', 'jmp']:
continue
visited = set()
current = 0
value = 0
inp = copy.deepcopy(orig)
print('-----')
print(inp[0])
while current not in visited:
print(current)
visited.add(current)
t = inp[current][0]
if current == nopcount:
if inp[current][0] == 'nop':
inp[current][0] = 'jmp'
else:
inp[current][0] = 'nop'
if (t != inp[current][0]):
print(t, inp[current][0], current, nopcount)
if inp[current][0] == 'nop':
current += 1
if inp[current][0] == 'jmp':
if inp[current][1][0] == '+':
current += int(inp[current][1][1:])
else:
current -= int(inp[current][1][1:])
if inp[current][0] == 'acc':
if inp[current][1][0] == '+':
value += int(inp[current][1][1:])
else:
value -= int(inp[current][1][1:])
current += 1
if inp[current][0] == 'end':
print('---', value)
return
print(value)
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')

1000
day09/data/data.txt Normal file

File diff suppressed because it is too large Load Diff

20
day09/data/sample.txt Normal file
View 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
View 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">&nbsp;&nbsp;&nbsp;<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&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F9&amp;related=ericwastl&amp;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
View 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')

94
day10/data/data.txt Normal file
View File

@@ -0,0 +1,94 @@
71
30
134
33
51
115
122
38
61
103
21
12
44
129
29
89
54
83
96
91
133
102
99
52
144
82
22
68
7
15
93
125
14
92
1
146
67
132
114
59
72
107
34
119
136
60
20
53
8
46
55
26
126
77
65
78
13
108
142
27
75
110
90
35
143
86
116
79
48
113
101
2
123
58
19
76
16
66
135
64
28
9
6
100
124
47
109
23
139
145
5
45
106
41

31
day10/data/sample.txt Normal file
View File

@@ -0,0 +1,31 @@
28
33
18
42
31
14
46
20
48
47
24
23
49
45
19
38
39
11
1
32
25
35
8
17
7
9
4
2
34
10
3

11
day10/data/sample4.txt Normal file
View File

@@ -0,0 +1,11 @@
16
10
15
5
1
11
7
19
6
12
4

188
day10/index.html Normal file
View File

@@ -0,0 +1,188 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<title>Day 10 - 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">18*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;<span class="title-event-wrap">0.0.0.0:</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://github.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">GitHub</a> - We&apos;re hiring engineers to make GitHub fast. Interested? Email fast@github.com with details of exceptional performance work you&apos;ve done in the past.</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 10: Adapter Array ---</h2><p>Patched into the aircraft's data port, you discover weather forecasts of a massive tropical storm. Before you can figure out whether it will impact your vacation plans, however, your device suddenly turns off!</p>
<p>Its battery is dead.</p>
<p>You'll need to plug it in. There's only one problem: the charging outlet near your seat produces the wrong number of <em>jolts</em>. Always prepared, you make a list of all of the joltage adapters in your bag.</p>
<p>Each of your joltage adapters is rated for a specific <em>output joltage</em> (your puzzle input). Any given adapter can take an input <code>1</code>, <code>2</code>, or <code>3</code> jolts <em>lower</em> than its rating and still produce its rated output joltage.</p>
<p>In addition, your device has a built-in joltage adapter rated for <em><code>3</code> jolts higher</em> than the highest-rated adapter in your bag. (If your adapter list were <code>3</code>, <code>9</code>, and <code>6</code>, your device's built-in adapter would be rated for <code>12</code> jolts.)</p>
<p>Treat the charging outlet near your seat as having an effective joltage rating of <code>0</code>.</p>
<p>Since you have some time to kill, you might as well test all of your adapters. Wouldn't want to get to your resort and realize you can't even charge your device!</p>
<p>If you <em>use every adapter in your bag</em> at once, what is the distribution of joltage differences between the charging outlet, the adapters, and your device?</p>
<p>For example, suppose that in your bag, you have adapters with the following joltage ratings:</p>
<pre><code>16
10
15
5
1
11
7
19
6
12
4
</code></pre>
<p>With these adapters, your device's built-in joltage adapter would be rated for <code>19 + 3 = <em>22</em></code> jolts, 3 higher than the highest-rated adapter.</p>
<p>Because adapters can only connect to a source 1-3 jolts lower than its rating, in order to use every adapter, you'd need to choose them like this:</p>
<ul>
<li>The charging outlet has an effective rating of <code>0</code> jolts, so the only adapters that could connect to it directly would need to have a joltage rating of <code>1</code>, <code>2</code>, or <code>3</code> jolts. Of these, only one you have is an adapter rated <code>1</code> jolt (difference of <em><code>1</code></em>).</li>
<li>From your <code>1</code>-jolt rated adapter, the only choice is your <code>4</code>-jolt rated adapter (difference of <em><code>3</code></em>).</li>
<li>From the <code>4</code>-jolt rated adapter, the adapters rated <code>5</code>, <code>6</code>, or <code>7</code> are valid choices. However, in order to not skip any adapters, you have to pick the adapter rated <code>5</code> jolts (difference of <em><code>1</code></em>).</li>
<li>Similarly, the next choices would need to be the adapter rated <code>6</code> and then the adapter rated <code>7</code> (with difference of <em><code>1</code></em> and <em><code>1</code></em>).</li>
<li>The only adapter that works with the <code>7</code>-jolt rated adapter is the one rated <code>10</code> jolts (difference of <em><code>3</code></em>).</li>
<li>From <code>10</code>, the choices are <code>11</code> or <code>12</code>; choose <code>11</code> (difference of <em><code>1</code></em>) and then <code>12</code> (difference of <em><code>1</code></em>).</li>
<li>After <code>12</code>, only valid adapter has a rating of <code>15</code> (difference of <em><code>3</code></em>), then <code>16</code> (difference of <em><code>1</code></em>), then <code>19</code> (difference of <em><code>3</code></em>).</li>
<li>Finally, your device's built-in adapter is always 3 higher than the highest adapter, so its rating is <code>22</code> jolts (always a difference of <em><code>3</code></em>).</li>
</ul>
<p>In this example, when using every adapter, there are <em><code>7</code></em> differences of 1 jolt and <em><code>5</code></em> differences of 3 jolts.</p>
<p>Here is a larger example:</p>
<pre><code>28
33
18
42
31
14
46
20
48
47
24
23
49
45
19
38
39
11
1
32
25
35
8
17
7
9
4
2
34
10
3
</code></pre>
<p>In this larger example, in a chain that uses all of the adapters, there are <em><code>22</code></em> differences of 1 jolt and <em><code>10</code></em> differences of 3 jolts.</p>
<p>Find a chain that uses all of your adapters to connect the charging outlet to your device's built-in adapter and count the joltage differences between the charging outlet, the adapters, and your device. <em>What is the number of 1-jolt differences multiplied by the number of 3-jolt differences?</em></p>
</article>
<p>To begin, <a href="10/input" target="_blank">get your puzzle input</a>.</p>
<form method="post" action="10/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=%22Adapter+Array%22+%2D+Day+10+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F10&amp;related=ericwastl&amp;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=%22Adapter+Array%22+%2D+Day+10+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F10'}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>

86
day10/module.py Normal file
View File

@@ -0,0 +1,86 @@
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)
inp.append(max(inp)+3)
print(sorted(inp))
last = 0
result = { 0: 0, 1: 0, 2:0, 3:0 }
for sample in sorted(inp):
result[sample - last] +=1
last = sample
print(result)
print(result[1] * result[3])
segments = []
for index, sample in enumerate(sorted(inp)):
if (sample - last) == 3:
segments.append(index)
last = sample
print(segments)
return segments
def p2(segments):
last = 0
count = 0
inp = get_input(pw)
inp.append(max(inp)+3)
inp = sorted(inp, reverse=True)
last = 0
result = { 0: 0, 1: 0, 2:0, 3:0 }
lst = [(0, inp)]
ok = True
parts = []
ls = 0
for segment in segments:
parts.append(inp[len(inp)-segment:len(inp)-ls])
ls = segment
pcount = []
lasts = 0
for part in parts:
lst = [(lasts, part)]
lasts = part[0]
ok = True
count = 0
while ok:
if len(lst) == 0:
break
sample = lst.pop()
last = sample[0]
newlst = sample[1][:]
while sample[0] - newlst[-1] >= -3:
if len(newlst) == 1:
count +=1
break
lst.insert(0, (newlst[-1], newlst[:-1]))
newlst.pop()
pcount.append(count)
print(pcount)
print(functools.reduce(lambda a,b: a*b, pcount))
return 0
result1 = None
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')

91
day11/data/data.txt Normal file
View File

@@ -0,0 +1,91 @@
LLLLLLLLLLLL.LLLLLLLLLL.LLLL.LLLL.LLLLLLLLLLL.LLLL.LLLLLLL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.LLLLLL.L
L.LLLLL.LL

200
day11/index.html Normal file
View File

@@ -0,0 +1,200 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<title>Day 11 - 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">20*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">0xffff&amp;</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://ximed.es/aoc" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Ximedes</a> - From Kotlin in the cloud to embedded NodeJS, our software powers payments worldwide. Join us in the Netherlands or Serbia!</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 11: Seating System ---</h2><p>Your plane lands with plenty of time to spare. The final leg of your journey is a ferry that goes directly to the tropical island where you can finally start your vacation. As you reach the waiting area to board the ferry, you realize you're so early, nobody else has even arrived yet!</p>
<p>By modeling the process people use to choose (or abandon) their seat in the waiting area, you're pretty sure you can predict the best place to sit. You make a quick map of the seat layout (your puzzle input).</p>
<p>The seat layout fits neatly on a grid. Each position is either floor (<code>.</code>), an empty seat (<code>L</code>), or an occupied seat (<code>#</code>). For example, the initial seat layout might look like this:</p>
<pre><code>L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL
</code></pre>
<p>Now, you just need to model the people who will be arriving shortly. Fortunately, people are entirely predictable and always follow a simple set of rules. All decisions are based on the <em>number of occupied seats</em> adjacent to a given seat (one of the eight positions immediately up, down, left, right, or diagonal from the seat). The following rules are applied to every seat simultaneously:</p>
<ul>
<li>If a seat is <em>empty</em> (<code>L</code>) and there are <em>no</em> occupied seats adjacent to it, the seat becomes <em>occupied</em>.</li>
<li>If a seat is <em>occupied</em> (<code>#</code>) and <em>four or more</em> seats adjacent to it are also occupied, the seat becomes <em>empty</em>.</li>
<li>Otherwise, the seat's state does not change.</li>
</ul>
<p><span title="Floor... floor never changes.">Floor (<code>.</code>) never changes</span>; seats don't move, and nobody sits on the floor.</p>
<p>After one round of these rules, every seat in the example layout becomes occupied:</p>
<pre><code>#.##.##.##
#######.##
#.#.#..#..
####.##.##
#.##.##.##
#.#####.##
..#.#.....
##########
#.######.#
#.#####.##
</code></pre>
<p>After a second round, the seats with four or more occupied adjacent seats become empty again:</p>
<pre><code>#.LL.L#.##
#LLLLLL.L#
L.L.L..L..
#LLL.LL.L#
#.LL.LL.LL
#.LLLL#.##
..L.L.....
#LLLLLLLL#
#.LLLLLL.L
#.#LLLL.##
</code></pre>
<p>This process continues for three more rounds:</p>
<pre><code>#.##.L#.##
#L###LL.L#
L.#.#..#..
#L##.##.L#
#.##.LL.LL
#.###L#.##
..#.#.....
#L######L#
#.LL###L.L
#.#L###.##
</code></pre>
<pre><code>#.#L.L#.##
#LLL#LL.L#
L.L.L..#..
#LLL.##.L#
#.LL.LL.LL
#.LL#L#.##
..L.L.....
#L#LLLL#L#
#.LLLLLL.L
#.#L#L#.##
</code></pre>
<pre><code>#.#L.L#.##
#LLL#LL.L#
L.#.L..#..
#L##.##.L#
#.#L.LL.LL
#.#L#L#.##
..L.L.....
#L#L##L#L#
#.LLLLLL.L
#.#L#L#.##
</code></pre>
<p>At this point, something interesting happens: the chaos stabilizes and further applications of these rules cause no seats to change state! Once people stop moving around, you count <em><code>37</code></em> occupied seats.</p>
<p>Simulate your seating area by applying the seating rules repeatedly until no seats change state. <em>How many seats end up occupied?</em></p>
</article>
<p>To begin, <a href="11/input" target="_blank">get your puzzle input</a>.</p>
<form method="post" action="11/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=%22Seating+System%22+%2D+Day+11+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F11&amp;related=ericwastl&amp;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=%22Seating+System%22+%2D+Day+11+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F11'}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>

134
day11/module.py Normal file
View File

@@ -0,0 +1,134 @@
from aoc.input import get_input
import copy
import itertools
import time
import collections
import re
from aoc.partselector import part_one, part_two, draw
import functools
def pw(line):
return list(line.strip())
def p1():
inp = get_input(pw)
width = len(inp[0])
height = len(inp)
grid = [['' for y in x] for x in inp]
for y, sample in enumerate(inp):
for x, o in enumerate(sample):
grid[y][x] = o
changed = True
adj = [(-1, 0), (0, -1), (1, 0), (0, 1), (1,-1), (1,1), (-1, 1), (-1, -1)]
while changed:
newgrid = copy.copy(grid)
ccnt = 0
changed = False
for y in range(height):
for x in range(width):
count = 0
for ax, ay in adj:
try:
if grid[y+ay][x+ax] == '#':
count += 1
except:
pass
if count == 0 and grid[y][x] == 'L':
newgrid[y][x] = '#'
changed = True
ccnt += 1
if count >= 4 and grid[y][x] == '#':
newgrid[y][x] = 'L'
changed = True
ccnt += 1
grid = newgrid
count = 0
for y in range(height):
for x in range(width):
if draw():
print(grid[y][x], end='')
if grid[y][x] == '#':
count += 1
if draw():
print()
print(count)
return inp
def p2(inp):
width = len(inp[0])
height = len(inp)
grid = [['' for y in x] for x in inp]
for y, sample in enumerate(inp):
for x, o in enumerate(sample):
grid[y][x] = o
changed = True
adj = [(-1, 0), (0, -1), (1, 0), (0, 1), (1,-1), (1,1), (-1, 1), (-1, -1)]
while changed:
newgrid = copy.copy(grid)
ccnt = 0
changed = False
for y in range(height):
for x in range(width):
if grid[y][x] == '.':
continue
count = 0
for ax, ay in adj:
ax1 = ax
ay1 = ay
while True:
try:
if grid[y+ay][x+ax] == '.':
ax += ax1
ay += ay1
else:
break
except:
break
try:
if grid[y+ay][x+ax] == '#':
count += 1
except:
pass
if count == 0 and grid[y][x] == 'L':
newgrid[y][x] = '#'
changed = True
ccnt += 1
if count >= 5 and grid[y][x] == '#':
newgrid[y][x] = 'L'
changed = True
ccnt += 1
grid = newgrid
count = 0
for y in range(height):
for x in range(width):
if draw():
print(grid[y][x], end='')
if grid[y][x] == '#':
count += 1
if draw():
print()
print(count)
return inp
result1 = None
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')

764
day12/data/data.txt Normal file

File diff suppressed because it is too large Load Diff

5
day12/data/sample.txt Normal file
View File

@@ -0,0 +1,5 @@
F10
N3
F7
R90
F11

149
day12/index.html Normal file
View File

@@ -0,0 +1,149 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<title>Day 12 - 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">22*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">λ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://github.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">GitHub</a> - We&apos;re hiring engineers to make GitHub fast. Interested? Email fast@github.com with details of exceptional performance work you&apos;ve done in the past.</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 12: Rain Risk ---</h2><p>Your ferry made decent progress toward the island, but the storm came in <span title="At least it wasn't a Category Six!">faster than anyone expected</span>. The ferry needs to take <em>evasive actions</em>!</p>
<p>Unfortunately, the ship's navigation computer seems to be malfunctioning; rather than giving a route directly to safety, it produced extremely circuitous instructions. When the captain uses the <a href="https://en.wikipedia.org/wiki/Public_address_system" target="_blank">PA system</a> to ask if anyone can help, you quickly volunteer.</p>
<p>The navigation instructions (your puzzle input) consists of a sequence of single-character <em>actions</em> paired with integer input <em>values</em>. After staring at them for a few minutes, you work out what they probably mean:</p>
<ul>
<li>Action <em><code>N</code></em> means to move <em>north</em> by the given value.</li>
<li>Action <em><code>S</code></em> means to move <em>south</em> by the given value.</li>
<li>Action <em><code>E</code></em> means to move <em>east</em> by the given value.</li>
<li>Action <em><code>W</code></em> means to move <em>west</em> by the given value.</li>
<li>Action <em><code>L</code></em> means to turn <em>left</em> the given number of degrees.</li>
<li>Action <em><code>R</code></em> means to turn <em>right</em> the given number of degrees.</li>
<li>Action <em><code>F</code></em> means to move <em>forward</em> by the given value in the direction the ship is currently facing.</li>
</ul>
<p>The ship starts by facing <em>east</em>. Only the <code>L</code> and <code>R</code> actions change the direction the ship is facing. (That is, if the ship is facing east and the next instruction is <code>N10</code>, the ship would move north 10 units, but would still move east if the following action were <code>F</code>.)</p>
<p>For example:</p>
<pre><code>F10
N3
F7
R90
F11
</code></pre>
<p>These instructions would be handled as follows:</p>
<ul>
<li><code>F10</code> would move the ship 10 units east (because the ship starts by facing east) to <em>east 10, north 0</em>.</li>
<li><code>N3</code> would move the ship 3 units north to <em>east 10, north 3</em>.</li>
<li><code>F7</code> would move the ship another 7 units east (because the ship is still facing east) to <em>east 17, north 3</em>.</li>
<li><code>R90</code> would cause the ship to turn right by 90 degrees and face <em>south</em>; it remains at <em>east 17, north 3</em>.</li>
<li><code>F11</code> would move the ship 11 units south to <em>east 17, south 8</em>.</li>
</ul>
<p>At the end of these instructions, the ship's <a href="https://en.wikipedia.org/wiki/Manhattan_distance" target="_blank">Manhattan distance</a> (sum of the absolute values of its east/west position and its north/south position) from its starting position is <code>17 + 8</code> = <em><code>25</code></em>.</p>
<p>Figure out where the navigation instructions lead. <em>What is the Manhattan distance between that location and the ship's starting position?</em></p>
</article>
<p>To begin, <a href="12/input" target="_blank">get your puzzle input</a>.</p>
<form method="post" action="12/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=%22Rain+Risk%22+%2D+Day+12+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F12&amp;related=ericwastl&amp;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=%22Rain+Risk%22+%2D+Day+12+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F12'}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>

96
day12/module.py Normal file
View File

@@ -0,0 +1,96 @@
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):
l = line.strip()
return l[0], int(l[1:])
def p1():
inp = get_input(pw)
go = {
'N': (0, -1),
'S': (0, 1),
'W': (-1, 0),
'E': (1, 0),
}
pos = (0, 0)
doffset = 1
for sample in inp:
print(sample)
d, v, = sample
if sample[0] in 'NWSE':
pos = (pos[0] + sample[1]*go[d][0],pos[1] + sample[1]*go[d][1])
if d == 'L':
doffset -= v//90
if d == 'R':
doffset += v//90
if d == 'F':
di = 'NESW'
d = di[doffset%4]
pos = (pos[0] + sample[1]*go[d][0],pos[1] + sample[1]*go[d][1])
print(pos)
print(pos)
print(abs(pos[0]) + abs(pos[1]))
return inp
def p2(inp):
go = {
'N': (0, -1),
'S': (0, 1),
'W': (-1, 0),
'E': (1, 0),
}
pos = (0, 0)
wp = (10, -1)
doffset = 1
for sample in inp:
print(sample)
d, v, = sample
if sample[0] in 'NWSE':
wp = (wp[0] + sample[1]*go[d][0],wp[1] + sample[1]*go[d][1])
if d == 'L':
doffset -= v//90
dd = (v//90)%4
if dd == 2:
wp = (-wp[0], -wp[1])
if dd == 1:
wp = (wp[1], -wp[0])
if dd == 3:
wp = (-wp[1], wp[0])
if d == 'R':
dd = (v//90)%4
if dd == 2:
wp = (-wp[0], -wp[1])
if dd == 3:
wp = (wp[1], -wp[0])
if dd == 1:
wp = (-wp[1], wp[0])
if d == 'F':
pos = (pos[0] + sample[1]*wp[0],pos[1] + sample[1]*wp[1])
print(pos, wp)
print(abs(pos[0]) + abs(pos[1]))
return 0
result1 = None
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')

2
day13/data/data.txt Normal file
View File

@@ -0,0 +1,2 @@
1002462
37,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,601,x,x,x,x,x,x,x,x,x,x,x,19,x,x,x,x,17,x,x,x,x,x,23,x,x,x,x,x,29,x,443,x,x,x,x,x,x,x,x,x,x,x,x,13

2
day13/data/sample.txt Normal file
View File

@@ -0,0 +1,2 @@
939
7,13,x,x,59,x,31,19

155
day13/index.html Normal file
View File

@@ -0,0 +1,155 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<title>Day 13 - 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">24*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">var 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://github.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">GitHub</a> - We&apos;re hiring engineers to make GitHub fast. Interested? Email fast@github.com with details of exceptional performance work you&apos;ve done in the past.</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 13: Shuttle Search ---</h2><p>Your ferry can make it safely to a nearby port, but it won't get much further. When you call to book another ship, you discover that no ships embark from that port to your vacation island. You'll need to get from the port to the nearest airport.</p>
<p>Fortunately, a shuttle bus service is available to bring you from the sea port to the airport! Each bus has an ID number that also indicates <em>how often the bus leaves for the airport</em>.</p>
<p>Bus schedules are defined based on a <em>timestamp</em> that measures the <em>number of minutes</em> since some fixed reference point in the past. At timestamp <code>0</code>, every bus simultaneously departed from the sea port. After that, each bus travels to the airport, then various other locations, and finally returns to the sea port to repeat its journey forever.</p>
<p>The time this loop takes a particular bus is also its ID number: the bus with ID <code>5</code> departs from the sea port at timestamps <code>0</code>, <code>5</code>, <code>10</code>, <code>15</code>, and so on. The bus with ID <code>11</code> departs at <code>0</code>, <code>11</code>, <code>22</code>, <code>33</code>, and so on. If you are there when the bus departs, you can ride that bus to the airport!</p>
<p>Your notes (your puzzle input) consist of two lines. The first line is your estimate of the <em>earliest timestamp you could depart on a bus</em>. The second line lists the bus IDs that are in service according to the shuttle company; entries that show <code>x</code> must be out of service, so you decide to ignore them.</p>
<p>To save time once you arrive, your goal is to figure out <em>the earliest bus you can take to the airport</em>. (There will be exactly one such bus.)</p>
<p>For example, suppose you have the following notes:</p>
<pre><code>939
7,13,x,x,59,x,31,19
</code></pre>
<p>Here, the earliest timestamp you could depart is <code>939</code>, and the bus IDs in service are <code>7</code>, <code>13</code>, <code>59</code>, <code>31</code>, and <code>19</code>. Near timestamp <code>939</code>, these bus IDs depart at the times marked <code>D</code>:</p>
<pre><code>time bus 7 bus 13 bus 59 bus 31 bus 19
929 . . . . .
930 . . . D .
931 D . . . D
932 . . . . .
933 . . . . .
934 . . . . .
935 . . . . .
936 . D . . .
937 . . . . .
938 D . . . .
<em>939 . . . . .</em>
940 . . . . .
941 . . . . .
942 . . . . .
943 . . . . .
<em>944 . . D . .</em>
945 D . . . .
946 . . . . .
947 . . . . .
948 . . . . .
949 . D . . .
</code></pre>
<p>The earliest bus you could take is bus ID <code>59</code>. It doesn't depart until timestamp <code>944</code>, so you would need to wait <code>944 - 939 = 5</code> minutes before it departs. Multiplying the bus ID by the number of minutes you'd need to wait gives <em><code>295</code></em>.</p>
<p><em>What is the ID of the earliest bus you can take to the airport multiplied by the number of minutes you'll need to wait for that bus?</em></p>
</article>
<p>To begin, <a href="13/input" target="_blank">get your puzzle input</a>.</p>
<form method="post" action="13/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=%22Shuttle+Search%22+%2D+Day+13+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F13&amp;related=ericwastl&amp;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=%22Shuttle+Search%22+%2D+Day+13+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F13'}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>

70
day13/module.py Normal file
View File

@@ -0,0 +1,70 @@
from aoc.input import get_input
import math
import copy
import itertools
import time
import collections
import re
from aoc.partselector import part_one, part_two
import functools
def pw(line):
return line.strip().split(',')
def p1():
inp = get_input(pw)
start = int(inp[0][0])
busses = inp[1]
rb = []
for b in busses:
if b != 'x':
rb.append(b)
print(rb)
m = 0
for x in rb:
x = int(x)
if m < ((start % x)+x):
print (x, start % x)
m = (start % x)+x
return inp
def p2():
inp = get_input(pw)
busses = inp[1]
rb = []
mods = {}
for b in enumerate(busses):
if b[1] != 'x':
bn = int(b[1])
rb.append(bn)
mods[bn] = (- b[0]) % bn
r = rb[0]
val = mods[r]
for b in rb[1:]:
print(r, b)
while val % b != mods[b]:
val += r
r *= b
print(val)
return val
return 0
result1 = None
if part_one():
start = time.time()
result1 = p1()
print(round(1000*(time.time() - start), 2), 'ms')
if part_two():
start = time.time()
p2()
print(round(1000*(time.time() - start), 2), 'ms')

585
day14/data/data.txt Normal file

File diff suppressed because it is too large Load Diff

4
day14/data/sample.txt Normal file
View File

@@ -0,0 +1,4 @@
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

148
day14/index.html Normal file
View File

@@ -0,0 +1,148 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8"/>
<title>Day 14 - 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">26*</span></div></div><div><h1 class="title-event">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="title-event-wrap">/*</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://github.com/" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">GitHub</a> - We&apos;re hiring engineers to make GitHub fast. Interested? Email fast@github.com with details of exceptional performance work you&apos;ve done in the past.</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 14: Docking Data ---</h2><p>As your ferry approaches the sea port, the captain asks for your help again. The computer system that runs this port isn't compatible with the docking program on the ferry, so the docking parameters aren't being correctly initialized in the docking program's memory.</p>
<p>After a brief inspection, you discover that the sea port's computer system uses a strange <a href="https://en.wikipedia.org/wiki/Mask_(computing)" target="_blank">bitmask</a> system in its initialization program. Although you don't have the correct decoder chip handy, you can emulate it in software!</p>
<p>The initialization program (your puzzle input) can either update the bitmask or write a value to memory. Values and memory addresses are both 36-bit unsigned integers. For example, ignoring bitmasks for a moment, a line like <code>mem[8] = 11</code> would write the value <code>11</code> to memory address <code>8</code>.</p>
<p>The bitmask is always given as a string of 36 bits, written with the most significant bit (representing <code>2^35</code>) on the left and the least significant bit (<code>2^0</code>, that is, the <code>1</code>s bit) on the right. The current bitmask is applied to values immediately before they are written to memory: a <code>0</code> or <code>1</code> overwrites the corresponding bit in the value, while an <code>X</code> leaves the bit in the value unchanged.</p>
<p>For example, consider the following program:</p>
<pre><code>mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
mem[8] = 11
mem[7] = 101
mem[8] = 0
</code></pre>
<p>This program starts by specifying a bitmask (<code>mask = ....</code>). The mask it specifies will overwrite two bits in every written value: the <code>2</code>s bit is overwritten with <code>0</code>, and the <code>64</code>s bit is overwritten with <code>1</code>.</p>
<p>The program then attempts to write the value <code>11</code> to memory address <code>8</code>. By expanding everything out to individual bits, the mask is applied as follows:</p>
<pre><code>value: 000000000000000000000000000000001011 (decimal 11)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 00000000000000000000000000000<em>1</em>0010<em>0</em>1 (decimal 73)
</code></pre>
<p>So, because of the mask, the value <code>73</code> is written to memory address <code>8</code> instead. Then, the program tries to write <code>101</code> to address <code>7</code>:</p>
<pre><code>value: 000000000000000000000000000001100101 (decimal 101)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 00000000000000000000000000000<em>1</em>1001<em>0</em>1 (decimal 101)
</code></pre>
<p>This time, the mask has no effect, as the bits it overwrote were already the values the mask tried to set. Finally, the program tries to write <code>0</code> to address <code>8</code>:</p>
<pre><code>value: 000000000000000000000000000000000000 (decimal 0)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 00000000000000000000000000000<em>1</em>0000<em>0</em>0 (decimal 64)
</code></pre>
<p><code>64</code> is written to address <code>8</code> instead, overwriting the value that was there previously.</p>
<p>To initialize your ferry's docking program, you need the sum of all values left in memory after the initialization program completes. (The entire 36-bit address space begins initialized to the value <code>0</code> at every address.) In the above example, only two values in memory are not zero - <code>101</code> (at address <code>7</code>) and <code>64</code> (at address <code>8</code>) - producing a sum of <em><code>165</code></em>.</p>
<p>Execute the initialization program. <em>What is the sum of all values left in memory after it completes?</em></p>
</article>
<p>To begin, <a href="14/input" target="_blank">get your puzzle input</a>.</p>
<form method="post" action="14/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=%22Docking+Data%22+%2D+Day+14+%2D+Advent+of+Code+2020&amp;url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F14&amp;related=ericwastl&amp;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=%22Docking+Data%22+%2D+Day+14+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F14'}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>

104
day14/module.py Normal file
View File

@@ -0,0 +1,104 @@
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 line.strip()
def p1():
inp = get_input(pw)
mask = ''
mv = 0
memory = dict()
def applymask(mask, v):
mv = 0
r = 1
shift = 0
for x in reversed(mask):
if x == '0':
pass
if x == '1':
mv += r
if x == 'X':
if (v >> shift) & 0x01 > 0:
mv += r
r *= 2
shift += 1
return mv
for sample in inp:
t, v = sample.split (' = ')
if t == 'mask':
mask = v.strip()
else:
cell = t[4:-1]
memory[cell] = applymask(mask, int(v))
print(sum(memory.values()))
return inp
def p2(segments):
inp = get_input(pw)
mask = ''
mv = 0
memory = dict()
def applymask(mask, v):
mv = 0
r = 1
shift = 0
floating = []
for i, x in enumerate(reversed(mask)):
if x == '0':
if (v >> shift) & 0x01 > 0:
mv += r
if x == '1':
mv += r
if x == 'X':
floating.append(i)
r *= 2
shift += 1
for l in range(1, len(floating)+1):
n = mv
for f in itertools.combinations(floating, l):
n = mv
for f1 in f:
n = n | pow(2, f1)
yield n
yield mv
for sample in inp:
t, v = sample.split (' = ')
if t == 'mask':
mask = v.strip()
else:
cell = t[4:-1]
for x in applymask(mask, int(cell)):
memory[x] = int(v)
print(sum(memory.values()))
return inp
return 0
result1 = None
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')

1
day15/data/data.txt Normal file
View File

@@ -0,0 +1 @@
2,0,1,7,4,14,18

1
day15/data/sample.txt Normal file
View File

@@ -0,0 +1 @@
0,3,6

1
day15/index.html Normal file
View File

@@ -0,0 +1 @@
404 Not Found

27
day15/markus.py Normal file
View File

@@ -0,0 +1,27 @@
from timeit import default_timer as timer
start = timer()
lines = [line.strip() for line in open("data/data.txt")]
numbers = [int(x) for x in lines[0].split(",")]
D = {}
for i, num in enumerate(numbers):
D[num] = i
t = len(numbers) - 1
previous = numbers[-1]
end1 = None
while t < 30_000_000 - 1:
if end1 is None and t == 2020 - 1:
print(previous)
end1 = timer()
t += 1
new_previous = 0 if previous not in D else t - 1 - D[previous]
D[previous] = t - 1
previous = new_previous
end2 = timer()
print(previous)
print(f'Time for part 1: {end1 - start} seconds')
print(f'Time for part 2: {end2 - start} seconds')

64
day15/module.py Normal file
View File

@@ -0,0 +1,64 @@
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 line.strip().split(",")
def p1():
inp = get_input(pw)
nmbrs = []
for sample in inp:
print(sample)
for i in inp:
nmbrs.append(int(i))
last = inp[-1]
for i in range(len(inp), 30000000):
if last not in nmbrs or len(list(filter(lambda x: x == last, nmbrs))) == 1:
number = 0
else:
pos = len(nmbrs) - nmbrs[-2::-1].index(last) - 2
opos = len(nmbrs) - 1
number = opos - pos
print(i + 1, ":", number, number - i)
nmbrs.append(number)
last = number
return inp
def p2():
inp = get_input(pw)
nmbrs = {int(x): y + 1 for y, x in enumerate(inp[:-1])}
last = int(inp[-1])
for i in range(len(nmbrs) + 1, 30000000):
if last not in nmbrs:
nmbrs[last] = i
last = 0
else:
prev, nmbrs[last] = nmbrs[last], i
last = i - prev
print(last)
result1 = None
if part_one():
start = time.time()
result1 = p1()
print(round(1000 * (time.time() - start), 2), "ms")
if part_two():
start = time.time()
p2()
print(round(1000 * (time.time() - start), 2), "ms")

28
day15/pypy.py Normal file
View File

@@ -0,0 +1,28 @@
import copy
import itertools
import time
import collections
import re
import functools
def p2():
inp =[2,0,1,7,4,14,18]
nmbrs = {int(x): y + 1 for y, x in enumerate(inp[:-1])}
last = int(inp[-1])
for i in range(len(nmbrs) + 1, 30000000):
if last not in nmbrs:
nmbrs[last] = i
last = 0
else:
prev, nmbrs[last] = nmbrs[last], i
last = i - prev
print(last)
start = time.time()
p2()
print(round(1000 * (time.time() - start), 2), "ms")

270
day16/data/data.txt Normal file
View File

@@ -0,0 +1,270 @@
departure location: 33-430 or 456-967
departure station: 42-864 or 875-957
departure platform: 42-805 or 821-968
departure track: 34-74 or 93-967
departure date: 40-399 or 417-955
departure time: 30-774 or 797-950
arrival location: 50-487 or 507-954
arrival station: 34-693 or 718-956
arrival platform: 42-729 or 751-959
arrival track: 28-340 or 349-968
class: 49-524 or 543-951
duration: 40-372 or 397-951
price: 48-922 or 939-951
route: 33-642 or 666-960
row: 39-238 or 255-973
seat: 48-148 or 161-973
train: 50-604 or 630-971
type: 29-299 or 316-952
wagon: 45-898 or 921-966
zone: 34-188 or 212-959
your ticket:
137,173,167,139,73,67,61,179,103,113,163,71,97,101,109,59,131,127,107,53
nearby tickets:
122,945,480,667,824,475,800,224,297,602,673,513,641,524,835,981,54,184,60,721
692,125,595,331,803,765,721,249,729,162,226,523,821,137,297,588,296,299,720,318
851,112,324,163,805,544,563,372,590,228,264,590,290,491,799,677,881,573,584,476
318,471,224,717,144,113,521,320,280,234,522,833,515,514,543,630,128,221,279,65
466,234,233,845,296,757,675,841,113,135,464,732,220,575,769,693,231,187,548,756
179,471,485,215,287,334,848,153,546,473,238,675,487,56,595,484,279,366,692,858
532,422,215,370,552,577,171,757,58,686,169,830,849,52,422,128,218,630,424,419
113,466,896,241,98,552,339,561,55,564,279,757,514,825,124,842,464,668,222,358
547,888,333,370,221,20,834,100,555,339,721,860,557,477,430,635,230,467,290,840
599,166,826,588,831,129,188,669,74,820,640,876,669,825,231,163,280,282,64,474
514,565,628,543,603,801,231,483,363,371,278,564,398,720,556,473,358,673,148,757
723,881,767,799,351,674,876,695,477,124,677,267,265,565,425,462,272,284,769,266
921,573,359,52,270,641,760,895,839,352,998,293,229,116,579,181,551,567,238,726
986,255,256,123,278,598,804,270,517,774,515,632,232,220,639,329,171,465,517,846
763,596,876,799,214,229,238,96,756,771,516,543,553,354,731,185,295,518,586,135
840,137,108,516,146,523,63,22,481,74,462,472,759,474,123,329,834,825,187,262
107,252,603,161,596,824,168,371,581,674,98,290,722,521,113,456,363,136,317,356
559,68,116,319,666,358,513,70,54,565,61,173,822,838,851,726,213,271,866,161
921,892,120,833,370,216,552,275,317,331,539,231,584,183,593,821,60,161,768,284
666,352,219,890,517,939,423,92,862,179,552,828,163,668,71,463,231,138,476,98
118,642,252,480,719,845,366,106,477,337,144,844,54,511,292,372,636,338,565,474
74,420,487,832,769,922,454,358,670,832,583,349,722,338,113,171,876,148,104,604
126,118,630,119,864,858,260,183,213,762,689,515,334,862,640,3,463,635,940,487
333,233,271,323,371,722,817,234,257,281,422,399,98,821,182,882,161,797,641,327
717,364,887,179,578,325,522,683,580,99,178,134,219,106,724,688,827,892,596,520
486,224,570,876,352,677,677,637,127,63,232,459,359,548,668,996,762,462,516,633
235,105,725,922,571,179,632,176,821,884,597,65,54,693,676,23,524,765,64,683
296,464,398,464,163,577,567,856,840,634,474,519,675,685,255,435,673,277,721,258
318,261,881,99,339,590,594,803,520,764,417,335,797,399,286,716,554,594,515,122
462,565,762,668,284,469,550,723,333,836,422,334,114,690,424,533,230,774,182,571
861,228,321,476,129,332,351,474,996,642,848,551,261,831,126,287,288,323,753,264
131,328,270,164,857,54,543,462,365,237,364,592,755,334,832,861,736,238,295,108
601,275,424,237,188,856,551,216,74,223,572,876,841,572,416,889,597,543,266,892
428,339,679,457,275,471,798,319,335,821,545,72,361,273,854,641,275,535,365,576
519,603,690,54,239,174,722,365,175,826,367,581,474,262,278,99,456,329,729,421
546,942,220,640,570,473,602,261,10,514,586,512,581,569,718,275,472,474,883,850
421,634,561,238,729,487,481,172,238,728,366,465,105,761,586,141,798,719,530,805
729,137,73,295,186,141,119,100,473,407,671,797,878,427,522,184,279,232,940,137
457,215,637,118,187,991,170,275,569,942,291,769,878,761,71,285,575,826,667,763
362,319,706,476,123,474,751,148,457,946,888,65,630,179,568,480,668,585,147,862
849,889,62,366,671,356,985,684,561,939,593,827,95,470,257,798,593,883,93,164
423,457,421,514,805,318,774,111,180,756,841,596,327,572,210,547,864,276,722,487
482,721,730,762,471,546,263,569,774,350,886,763,766,266,127,457,803,255,508,320
728,831,221,464,102,557,134,96,260,845,849,944,769,858,603,480,555,841,356,455
759,363,635,328,691,824,372,766,684,761,278,104,280,17,70,548,858,369,852,831
279,98,479,724,729,474,281,321,734,102,267,860,880,326,766,331,58,843,140,187
353,672,854,358,285,558,841,789,178,264,518,922,137,331,592,639,766,892,93,288
51,213,238,804,352,760,401,100,225,350,894,765,851,165,689,62,636,725,339,269
123,112,977,297,852,823,101,264,143,859,507,169,65,328,133,221,755,270,399,774
338,766,810,359,685,634,687,94,279,584,849,366,231,480,887,365,287,640,757,67
365,19,68,358,949,284,597,461,826,187,51,51,768,586,894,841,136,604,461,52
720,834,558,298,518,474,162,278,845,771,328,212,942,220,297,259,219,645,823,939
765,121,564,852,580,557,666,921,482,175,430,488,511,886,595,761,213,363,554,216
338,681,126,580,821,68,467,401,144,524,892,801,349,128,110,846,426,319,556,550
773,532,604,65,64,271,461,292,562,97,134,173,947,598,545,102,335,233,258,669
757,364,284,57,523,877,62,803,229,318,484,7,106,56,61,518,179,559,186,61
854,469,21,370,226,124,581,889,420,515,298,563,459,522,66,631,599,563,480,508
354,139,130,146,274,94,468,94,847,633,170,895,259,218,571,162,126,717,569,118
889,74,181,860,887,229,127,841,359,724,55,256,328,324,629,553,284,127,631,72
287,74,842,99,798,522,687,205,857,823,847,60,186,425,575,486,475,683,358,166
321,584,458,770,602,851,727,349,234,599,510,234,575,635,761,579,587,280,158,106
689,767,844,113,260,263,467,674,537,64,131,268,263,217,227,139,272,943,637,168
365,279,76,577,825,281,847,258,553,73,145,846,523,176,805,136,124,517,170,895
666,424,255,601,291,719,773,640,479,792,120,586,753,182,802,458,584,291,591,107
882,824,725,135,473,215,399,602,768,322,946,1,583,583,366,338,277,878,575,268
836,63,214,183,349,337,948,510,694,336,176,839,473,275,425,686,519,54,634,590
425,949,797,639,589,218,69,729,940,719,875,102,285,167,995,351,110,398,553,260
864,101,270,256,767,551,667,692,631,473,18,831,561,840,567,173,564,514,418,140
355,753,153,862,457,671,689,756,291,298,116,168,842,297,641,349,137,339,280,264
550,322,365,226,782,721,51,514,855,545,418,143,823,372,71,562,476,232,636,372
317,123,224,299,400,424,895,131,468,276,773,575,765,880,474,467,724,115,421,687
352,879,933,100,848,681,339,292,718,894,104,51,510,67,803,860,462,329,854,596
802,631,485,552,519,115,597,359,195,583,677,220,213,291,600,943,583,128,237,548
568,603,127,727,524,320,840,281,63,104,763,639,590,327,854,51,257,5,102,676
470,635,576,805,921,144,105,545,760,519,884,418,235,226,138,596,883,806,944,426
600,856,129,723,851,773,683,577,287,97,130,419,171,568,797,226,528,844,949,320
800,726,353,213,686,479,480,428,753,243,166,231,58,270,828,883,329,323,892,855
823,176,769,358,258,265,551,469,102,62,61,603,465,477,755,941,939,263,790,167
463,123,478,604,63,889,946,272,592,851,600,58,458,294,789,946,551,464,224,863
368,357,803,282,168,863,267,164,232,358,468,588,121,136,575,57,54,63,697,145
485,134,798,270,826,832,882,109,673,266,321,295,545,564,483,483,290,451,590,944
886,430,258,603,119,419,116,226,881,526,518,137,69,892,590,165,136,181,577,141
249,220,751,551,364,234,112,835,554,949,127,238,752,278,676,59,727,265,233,477
641,554,556,857,67,771,146,120,588,853,947,429,586,517,543,576,119,483,718,496
555,464,839,511,423,325,71,234,227,113,98,601,134,604,692,580,274,11,187,474
485,588,60,172,894,51,55,118,424,65,891,295,74,428,24,336,68,566,766,63
295,136,295,566,763,295,558,458,364,128,480,118,98,826,817,63,366,360,326,578
467,592,692,596,547,635,98,723,126,594,822,584,667,350,349,309,860,763,578,668
365,96,862,896,560,417,361,566,62,64,168,241,588,121,267,335,352,365,260,170
275,803,233,397,501,423,548,676,692,112,94,828,428,364,103,579,834,58,183,799
893,100,859,57,621,222,114,828,685,555,845,720,363,457,238,272,765,98,671,169
213,803,466,863,156,334,804,771,821,568,113,836,360,289,598,172,182,71,565,691
765,595,986,219,727,365,331,424,564,886,105,352,474,726,121,879,852,593,97,875
591,470,102,197,319,62,316,94,417,464,945,229,237,229,138,223,942,568,921,288
334,350,832,830,826,860,545,147,604,326,102,322,146,598,675,929,507,295,518,118
687,74,669,832,847,555,577,491,259,890,854,185,175,186,474,586,340,357,561,898
419,830,677,884,173,358,120,357,757,317,146,681,177,322,110,772,518,56,198,839
221,469,352,771,527,467,420,844,512,566,512,553,226,177,180,887,758,589,73,97
522,201,846,326,371,428,293,850,283,269,148,894,894,220,947,227,921,98,129,512
559,66,529,148,458,478,116,551,804,56,170,768,371,134,883,121,798,672,827,766
520,680,72,60,456,476,822,799,71,161,882,508,636,688,188,71,353,267,244,693
135,168,175,805,751,515,427,802,859,171,277,571,835,742,338,886,97,674,895,512
633,838,360,457,547,761,942,457,67,871,590,117,599,557,798,876,678,673,329,421
462,331,755,898,679,324,171,884,588,290,792,299,188,895,891,256,222,256,887,257
51,182,329,846,758,259,794,577,641,858,630,356,424,636,146,224,262,822,261,851
256,828,108,360,827,361,504,949,257,425,948,770,856,890,111,369,846,850,463,360
690,483,480,797,323,755,278,463,856,203,271,351,285,172,318,862,829,221,71,513
639,802,123,897,762,762,137,799,586,604,839,679,229,174,73,748,188,330,363,338
855,579,232,335,438,884,690,273,799,674,584,470,289,334,690,171,944,640,476,261
669,350,414,418,482,163,287,756,544,559,855,113,835,600,801,236,947,430,463,857
878,262,719,331,361,135,182,61,144,337,881,594,479,255,555,897,488,683,519,668
272,229,464,782,797,468,767,167,864,885,826,462,324,128,317,325,126,230,898,109
512,946,667,417,316,637,73,555,884,172,165,458,771,485,982,216,890,273,575,768
890,137,290,466,865,218,281,292,638,875,949,603,678,225,257,686,352,879,96,834
60,325,860,216,948,276,482,809,120,834,230,223,827,861,57,939,423,361,484,147
274,516,360,599,320,177,764,767,507,885,177,100,514,589,468,662,876,553,365,763
565,680,594,832,463,107,863,170,231,101,71,939,978,67,53,175,682,161,65,861
147,766,941,351,892,842,280,162,555,358,699,851,590,921,687,334,294,297,273,98
296,52,877,294,586,354,60,69,804,319,427,862,510,601,297,846,111,761,848,189
552,555,298,840,324,589,472,805,635,51,759,940,826,329,867,689,68,805,876,283
834,597,852,675,50,825,474,572,473,723,478,594,226,857,236,325,169,495,108,679
66,944,878,146,74,112,761,585,466,589,548,805,515,569,353,462,883,745,765,59
797,894,101,884,296,840,214,172,172,878,51,683,839,466,97,381,69,293,544,281
65,120,559,839,470,175,363,724,283,773,691,898,182,481,707,858,290,554,214,97
756,888,762,897,56,521,172,862,603,487,357,862,274,128,721,774,168,159,724,597
217,463,722,845,462,68,198,510,226,175,581,118,753,103,760,556,351,229,275,456
364,723,766,359,147,287,264,425,358,93,821,578,753,371,667,133,475,486,813,130
428,771,561,845,944,224,323,54,173,507,423,147,163,603,184,793,765,368,564,364
515,948,130,186,727,939,366,174,214,282,726,760,945,99,878,55,553,683,949,982
633,577,827,263,885,100,826,397,483,639,758,728,473,480,587,232,428,204,848,293
64,756,60,738,277,679,862,856,685,133,429,424,858,177,222,229,290,276,667,601
129,515,420,294,853,636,676,236,338,361,727,691,176,583,566,188,692,83,590,558
475,825,421,797,762,669,766,922,461,318,262,631,768,224,123,245,107,290,849,880
877,720,468,480,14,481,290,349,828,219,175,635,675,674,948,672,113,271,55,456
564,601,481,560,361,798,641,236,846,164,943,769,669,143,506,99,634,554,427,844
947,596,825,843,941,422,638,554,222,839,318,59,517,148,398,861,463,362,326,996
288,128,225,829,235,827,672,184,284,824,720,285,890,465,825,726,838,562,399,406
939,726,371,298,897,773,137,73,287,227,147,266,350,770,632,757,583,557,312,720
723,669,257,328,352,471,117,285,369,273,465,884,469,326,93,168,97,408,635,170
633,672,789,760,333,124,669,726,69,399,725,878,554,281,834,275,561,255,944,332
228,271,301,677,946,823,327,577,684,320,547,893,567,834,261,117,333,222,947,333
998,335,165,946,218,122,478,591,279,263,593,678,756,225,857,563,457,565,666,773
884,227,201,894,481,637,633,641,798,463,543,281,641,316,425,922,570,462,471,888
514,579,563,131,680,113,285,268,828,515,56,215,130,666,888,106,216,867,217,483
475,71,510,464,352,858,528,825,349,484,804,727,549,483,106,484,70,334,294,456
17,521,840,458,766,945,232,185,291,298,761,755,267,544,679,521,213,888,803,850
559,65,877,724,357,122,768,855,124,889,720,332,53,860,225,217,135,320,497,228
562,181,270,799,715,896,840,128,120,470,135,370,299,945,589,668,221,233,119,226
582,721,123,603,119,580,280,421,633,228,508,564,675,668,163,70,524,930,125,823
559,603,184,879,421,255,238,574,557,492,461,116,255,117,473,117,944,545,729,369
228,895,691,894,330,637,586,274,231,742,274,508,480,366,886,339,580,851,331,178
766,220,431,69,886,484,691,588,133,355,280,773,561,847,590,281,176,138,363,771
633,281,97,881,740,633,483,554,323,803,507,288,767,143,115,571,186,327,521,224
759,138,212,829,481,129,699,102,237,922,524,357,549,947,840,108,369,797,754,235
427,858,257,811,823,898,73,476,332,888,398,363,290,112,298,476,263,898,685,284
505,803,296,258,889,322,69,337,425,468,418,274,322,486,107,289,545,397,177,132
559,586,560,840,203,281,297,639,544,165,475,949,139,558,63,891,581,52,95,886
851,715,140,220,854,835,482,555,370,726,797,296,62,798,140,422,511,426,338,113
878,592,801,331,573,118,600,585,567,94,13,922,601,97,546,800,285,471,722,558
329,372,826,423,66,117,102,949,241,367,120,636,688,267,277,597,692,169,520,558
233,558,559,364,225,429,105,266,361,773,688,589,147,73,137,856,547,771,467,529
763,361,275,949,592,896,225,743,755,567,139,604,668,184,802,879,107,461,585,683
563,423,595,268,286,173,484,363,169,224,68,570,422,584,718,500,507,558,678,217
895,574,428,424,119,861,360,689,280,670,298,684,875,140,69,806,590,603,583,941
883,850,496,484,122,318,109,136,834,363,101,334,366,226,822,270,218,851,231,292
398,472,549,329,724,887,831,609,801,828,212,516,424,841,221,881,875,319,133,858
573,316,106,685,644,548,633,751,550,507,553,227,139,573,351,147,579,587,145,797
359,279,106,833,296,423,164,562,882,181,246,418,284,850,175,878,213,684,186,236
729,802,426,822,420,600,14,469,142,186,93,321,726,727,182,182,126,64,829,358
290,833,399,540,423,599,513,830,863,829,844,686,278,561,372,859,168,801,50,64
856,636,257,546,560,267,129,981,515,470,887,691,886,358,683,72,837,576,217,898
833,97,594,220,827,477,591,332,762,186,755,356,183,522,581,876,826,61,410,213
418,551,321,1,883,640,570,632,673,481,119,859,364,169,686,485,226,641,55,467
70,721,799,767,564,898,429,802,68,323,196,557,583,353,324,773,894,580,174,50
182,127,71,719,638,885,358,849,725,834,508,586,337,799,984,277,176,881,99,799
185,354,329,66,635,842,568,362,804,234,278,979,886,72,845,591,483,282,226,281
733,128,878,99,821,522,836,284,282,320,758,290,456,485,893,295,690,674,671,277
475,109,212,499,282,896,475,875,285,486,758,356,138,546,939,220,524,842,362,362
589,370,6,119,256,112,579,363,520,117,761,328,164,565,470,121,360,722,99,265
944,339,215,889,893,364,835,100,756,418,234,147,270,600,224,472,522,276,835,241
586,847,463,124,851,363,670,232,357,143,168,337,945,356,424,109,69,147,655,836
823,759,523,981,581,188,830,636,600,480,567,945,173,139,95,475,670,71,458,945
683,105,222,471,757,426,293,334,133,510,753,827,898,693,600,187,598,514,477,708
167,666,514,215,727,214,64,547,891,860,595,420,560,262,247,180,855,146,284,429
864,285,430,291,599,588,291,275,101,449,418,896,885,275,521,476,219,474,50,601
761,576,549,57,576,316,861,226,683,636,402,520,759,100,136,849,830,841,521,146
753,744,138,800,355,143,55,137,212,669,922,947,593,426,318,102,587,95,549,53
471,58,10,318,256,336,460,681,175,755,288,762,148,371,70,587,757,487,212,333
547,281,296,475,834,756,544,718,890,353,68,419,327,564,729,944,584,137,930,53
512,213,840,798,729,557,878,671,856,841,488,549,279,130,464,877,602,349,837,419
726,178,976,327,573,257,103,554,774,671,114,330,323,581,359,372,362,833,365,371
682,232,261,65,763,292,148,107,574,270,638,674,757,719,339,159,109,641,353,173
602,259,420,641,820,762,96,68,475,460,825,679,547,128,420,74,666,835,556,477
351,720,580,333,851,861,108,842,689,601,684,600,234,638,528,922,474,729,213,175
511,69,430,562,686,854,252,128,295,285,424,478,857,798,180,729,329,585,766,772
368,581,726,468,677,482,874,765,218,468,67,637,570,471,284,834,834,862,726,477
487,765,167,60,64,420,356,328,475,336,130,471,842,545,232,341,101,59,889,275
802,363,666,940,799,109,429,226,165,266,370,175,680,826,272,551,690,849,613,852
725,144,662,568,168,557,512,594,340,580,166,171,418,257,841,69,70,107,463,591
53,764,523,478,685,327,264,876,633,79,340,888,109,543,832,162,771,179,368,479
576,172,939,102,268,835,802,355,559,581,339,418,825,236,583,5,949,299,318,55
468,545,519,339,758,577,734,365,563,563,364,637,893,459,282,856,689,164,461,639
947,132,169,855,363,855,105,171,463,689,463,1,842,473,120,428,479,221,830,335
174,558,423,689,633,679,601,431,281,163,271,164,824,399,838,692,362,231,469,65
550,101,125,417,604,328,603,145,883,9,326,278,470,93,324,109,116,678,133,825
798,754,487,757,852,214,578,863,885,562,171,751,117,127,985,690,148,107,289,805
564,427,115,590,349,582,672,844,561,263,264,267,496,889,326,280,521,835,821,184
685,237,397,514,843,285,638,116,553,860,290,892,670,843,264,850,55,471,449,478
173,855,765,221,99,566,839,681,853,562,573,993,425,428,728,259,692,424,283,690
844,461,358,447,557,848,426,171,275,948,146,119,326,183,842,760,680,361,472,554
227,508,554,549,461,129,546,524,320,226,95,552,353,800,511,192,337,258,939,339
676,135,462,259,948,324,673,867,173,286,566,804,773,134,420,61,165,96,462,886
276,640,868,631,171,368,473,719,517,831,681,679,106,518,214,941,277,875,883,758
754,165,982,673,849,61,335,894,680,165,169,139,602,228,185,466,550,428,850,857
125,268,521,265,884,278,115,825,591,50,860,469,509,831,863,132,889,554,345,727
679,725,112,473,479,634,515,127,467,174,740,758,853,73,226,561,283,753,487,851
564,124,684,340,326,880,858,353,692,233,674,674,236,174,435,679,552,117,168,337
522,52,280,552,948,351,269,118,587,636,163,722,353,269,110,79,97,294,329,289
594,500,689,95,862,693,468,121,114,108,100,574,692,826,559,167,831,220,523,589
169,220,181,178,563,847,853,682,276,161,524,65,398,186,895,850,136,757,597,989
63,555,833,411,477,74,481,74,95,846,295,321,755,350,360,571,941,113,107,340
327,876,881,52,672,53,840,419,237,641,631,571,97,940,132,634,265,669,755,738
875,851,642,843,562,765,320,288,754,774,161,641,216,215,288,624,690,805,596,141
765,126,326,572,679,265,772,330,229,666,440,804,105,921,516,169,827,884,939,134
234,858,587,99,549,51,282,847,362,712,101,567,521,882,677,231,591,769,684,630
372,413,365,179,672,570,759,63,545,485,71,860,350,138,638,141,562,892,829,549
354,863,284,174,330,269,829,124,140,111,945,832,522,671,421,134,635,618,107,322
128,805,331,682,349,427,821,634,362,678,592,518,845,805,176,400,850,688,363,324
264,146,60,429,638,888,293,112,487,577,320,339,667,886,83,177,177,140,226,232
857,456,825,116,279,766,693,162,637,69,549,754,165,143,836,591,227,778,519,595
142,520,370,939,225,397,60,515,172,584,188,487,890,799,770,597,678,123,77,238
263,418,513,718,280,996,67,266,418,183,147,145,592,765,753,457,397,362,339,884
946,943,726,187,134,466,578,359,693,185,360,827,589,223,349,523,233,18,685,54
180,832,7,58,637,367,214,475,161,630,850,837,72,261,596,420,840,132,478,294
946,334,366,291,486,832,107,719,506,123,691,110,102,220,550,97,483,356,693,95
821,668,145,728,836,947,515,675,24,550,512,132,259,679,571,232,630,285,103,131
721,939,419,187,766,337,470,530,233,727,62,546,265,726,64,603,104,881,637,480
461,672,297,640,686,549,58,569,142,593,851,487,544,861,426,161,562,243,275,368
756,162,58,220,827,136,123,457,520,675,590,175,217,227,756,257,0,687,760,65
771,515,100,879,584,107,148,765,839,267,293,360,284,465,582,356,340,56,740,862
562,398,557,466,833,688,291,632,354,183,757,476,834,845,583,93,249,521,804,875
277,582,224,563,263,421,129,670,598,945,340,366,675,839,336,873,143,258,892,286
543,399,67,398,636,861,101,547,127,127,994,325,285,257,943,273,270,722,429,581
671,836,668,824,90,171,94,681,485,862,429,215,231,565,462,580,366,881,276,185
753,278,362,231,19,337,881,94,212,563,371,320,853,229,235,686,219,426,802,366

0
day16/data/sample.txt Normal file
View File

1
day16/index.html Normal file
View File

@@ -0,0 +1 @@
404 Not Found

125
day16/module.py Normal file
View File

@@ -0,0 +1,125 @@
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 line.strip()
def p1():
inp = get_input(pw)
rules_tmp = [x.split(': ') for x in inp[0:20]]
my = inp[22].split(',')
nearby = [list(map(int, x.split(','))) for x in inp[25:]]
rules = {}
for r in rules_tmp:
rules[r[0]] = list(map(lambda x: list(map(int, x.split('-'))), r[1].split(' or ')))
print(rules)
count = 0
for n in nearby:
valid = True
for field in n:
fvalid = []
for r in rules.values():
tvalid = []
for rr in r:
tvalid.append(field > rr[0] and field < rr[1])
fvalid.append(any(tvalid))
if not any(fvalid):
count += field
pass
print(count)
return inp
def p2():
inp = get_input(pw)
rules_tmp = [x.split(': ') for x in inp[0:20]]
my = list(map(int, inp[22].split(',')))
nearby = [list(map(int, x.split(','))) for x in inp[25:]]
rules = {}
for r in rules_tmp:
rules[r[0]] = list(map(lambda x: list(map(int, x.split('-'))), r[1].split(' or ')))
print(rules)
count = 0
vtickets = []
print(len(nearby))
for n in nearby:
valid = []
for field in n:
fvalid = []
for r in rules.values():
tvalid = []
for rr in r:
tvalid.append(field >= rr[0] and field <= rr[1])
fvalid.append(any(tvalid))
valid.append(any(fvalid))
if all(valid):
vtickets.append(n)
print(len(vtickets))
print(my)
vtickets.append(my)
fields = collections.defaultdict(list)
for name, r in rules.items():
for i in range(len(my)):
rvalid = []
for n in vtickets:
field = n[i]
tvalid = []
for rr in r:
tvalid.append(field >= rr[0] and field <= rr[1])
rvalid.append(any(tvalid))
if all(rvalid):
fields[i].append(name)
print(i, name)
newfields = copy.copy(fields)
print('------')
realfields = {}
for i in range(len(fields)):
i, f = sorted(newfields.items(), key=lambda x: len(x[1]), reverse=False)[0]
v = f[0]
del newfields[i]
realfields[i] = v
for i2, f2 in fields.items():
if v in f2:
f2.remove(v)
fields[i2] = f2
value = 1
for i, v in realfields.items():
if v.startswith('departure'):
value *= my[i]
print(value)
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()
print(round(1000*(time.time() - start), 2), 'ms')

8
day17/data/data.txt Normal file
View File

@@ -0,0 +1,8 @@
#...#.#.
..#.#.##
..#..#..
.....###
...#.#.#
#.#.##..
#####...
.#.#.##.

3
day17/data/sample.txt Normal file
View File

@@ -0,0 +1,3 @@
.#.
..#
###

1
day17/index.html Normal file
View File

@@ -0,0 +1 @@
404 Not Found

129
day17/module.py Normal file
View File

@@ -0,0 +1,129 @@
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 line.strip()
def p1():
inp = get_input(pw)
cube = {}
print(inp)
ymin = 0
xmin = 0
zmin = 0
ymax = len(inp)-1
xmax = len(inp[0]) - 1
zmax = 0
for y, sample in enumerate(inp):
z = 0
for x, v in enumerate(sample):
if v == '#':
cube[(x, y, z)] = v
arround = [(x,y,z) for x in range(-1, 2) for y in range(-1, 2) for z in range(-1, 2)]
for _ in range(6):
newcube = {}
for zi in range(zmin-1, zmax+2):
for yi in range(ymin-1, ymax+2):
for xi in range(xmin-1, xmax+2):
count = 0
for xo, yo, zo in arround:
if xo == 0 and yo == 0 and zo == 0:
continue
if (xi+xo, yi+yo, zi+zo) in cube:
#print((xi+xo, yi+yo, zi+zo), '#')
count += 1
#print((xi, yi, zi), count)
if (xi, yi, zi) in cube:
if count in [2,3]:
newcube[(xi, yi, zi)] = '#'
else:
if count == 3:
newcube[(xi, yi, zi)] = '#'
zmin -= 1
zmax += 1
ymin -= 1
ymax += 1
xmin -= 1
xmax += 1
cube = copy.copy(newcube)
print(len(cube))
print(len(cube))
return inp
def p2():
inp = get_input(pw)
plane = inp
cube = set()
print(inp)
ymin = 0
xmin = 0
zmin = 0
ymax = len(inp)-1
xmax = len(inp[0]) - 1
zmax = 0
wmax = 0
wmin = 0
for y, sample in enumerate(inp):
z = 0
for x, v in enumerate(sample):
if v == '#':
cube.add((x, y, z, 0))
arround = [(x,y,z, w) for x in range(-1, 2) for y in range(-1, 2) for z in range(-1, 2) for w in range(-1, 2)]
for _ in range(6):
newcube = set()
for wi in range(wmin-1, wmax+2):
for zi in range(zmin-1, zmax+2):
for yi in range(ymin-1, ymax+2):
for xi in range(xmin-1, xmax+2):
count = 0
for xo, yo, zo, wo in arround:
if xo == 0 and yo == 0 and zo == 0 and wo == 0:
continue
if (xi+xo, yi+yo, zi+zo, wi+wo) in cube:
#print((xi+xo, yi+yo, zi+zo), '#')
count += 1
#print((xi, yi, zi), count)
if (xi, yi, zi, wi) in cube:
if count in [2,3]:
newcube.add((xi, yi, zi, wi))
else:
if count == 3:
newcube.add((xi, yi, zi, wi))
wmin -= 1
wmax += 1
zmin -= 1
zmax += 1
ymin -= 1
ymax += 1
xmin -= 1
xmax += 1
cube = copy.copy(newcube)
print(len(cube))
print(len(cube))
return inp
return 0
result1 = None
if part_one():
start = time.time()
result1 = p1()
print(round(1000*(time.time() - start), 2), 'ms')
if part_two():
start = time.time()
p2()
print(round(1000*(time.time() - start), 2), 'ms')

373
day18/data/data.txt Normal file
View File

@@ -0,0 +1,373 @@
3 + 8
7 * (7 * 6 + 7 * 5 + (9 + 2 * 2 * 4)) + 7 * 3 * 5
3 * 4 + 2 + 7 + (4 * (9 + 9 + 2 + 3 * 8) + 9 + (6 + 4) + 7) + 3
(7 * 9 + 2 + (5 + 4)) + 5 + 9
4 + 5 * 5 + 8 + (3 * (7 * 7 + 5) * 7) * 5
2 + 8 * (5 + 4 * (8 * 3 * 6 * 7 * 8 * 8) + 8 * (7 + 9 + 8 * 9 * 4) * (3 + 9 * 5 + 2 + 5 * 4)) * 4
(8 * (3 + 3 * 9) * 3 * 9 * 9) + 3
(8 * 2 * 4 + 5) * 2 + 2 + (3 + 4 * 2 * 3 + (4 + 7 + 8 * 7 * 5) * (9 + 9 * 8))
(7 + 2 + (2 * 3)) * ((8 + 3 * 4 + 3 + 9 + 4) + 5) + 8 * 7 + 5 * 5
7 + (3 + 6 + 8) + (5 * 9 + 7 + 2 + (2 * 9 + 8) + 2) * 9
8 + 4 * 4 * 6 + 9 + ((5 + 8) + 7)
(6 + (8 + 6 * 8 + 7 + 3 * 3) + 5 + 7 * 6 + 8) * 2 * 2 * 5 * 2 * 4
(4 + (7 * 4 + 7 * 3 * 9 + 2) * 6 * 2 + 6) * (8 + 5 * 6 * (3 + 3 * 8 + 3) * 9) + 9
7 + 9 * ((5 + 8 * 5 * 6) * 2 * 5) + 9 + 9 * (6 * 8 * 4 + 3)
4 + (8 * 7 * 7 + 9) + (7 * 9 + 4) + 5 * 3 + 6
7 + (3 + 6) * (5 * (5 * 7 + 5 * 6 + 3 + 3) + (3 * 4) * 8) * 2 * 4
2 + (6 * 7 * 8 * 6 + (7 + 4 * 3 + 3 * 2 * 9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+ 5 + 8 * 7 + (7 * 7 + 6 + 2 + 8))
(7 * 2 * (4 + 2 + 7 * 5 * 6 * 5) * (3 * 4 + 2) + 6) + 9 + 5 + 3
4 * 5 * ((5 + 9 * 7 + 2) + 4 * 7 + 9) + 9 + 7
7 * 2 * 6 + 9 + 5 * 6
3 + 3 * 7 * ((3 * 3 + 2 + 7 * 5 + 2) + 7 * 6 * 2 * 5 * 9) + (4 * 5) + 7
9 + ((5 + 5 * 7) + 7 * 2) + 7 + 6
4 * 9 * 9 + ((9 + 3 + 7 * 4) * 4 + 2 + 9 + 8 + 6) * 6
(6 * 2 * 5 + 4 + 5) + (8 + (8 * 5 + 7 * 7 + 6 * 2) * 6 + 6) + 4 * 8
(5 + 6 * 2) * 5 * 6 * (5 * 5) + 9
(7 + (9 * 4)) * ((4 + 3 + 5) + 7 * 5)
2 * 5 + ((9 * 6 * 3 * 6 + 4) * 9 * 4) * 2 * 3 * (8 + 6)
3 * 6 * 5 + 9 * (6 + 4 * 2 + 5 * 6)
((7 + 8) + 3 + 7 + (8 * 3 * 6 + 8) * 2) * ((3 * 5 * 9) + 5) * 8 + 8
((3 * 4 + 5 + 2) + 6 * 6) * 9
4 + 6 * (9 * 6 * 7 + (2 * 5 + 5 * 9 + 6)) * 8
4 * (2 + 2 + 9) + 5 + 5 * ((5 + 3) + 4 * 7)
6 + 8 * 3 + 4
2 + 8 + (8 + (7 + 5 * 3 * 8 * 7 + 2) * 6) + 3

5
day18/data/sample.txt Normal file
View File

@@ -0,0 +1,5 @@
1 + (2 * 3) + (4 * (5 + 6))
2 * 3 + (4 * 5)
5 + (8 * 3 + 9 + 3 * 4 * 3)
5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))
((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2

1
day18/index.html Normal file
View File

@@ -0,0 +1 @@
404 Not Found

125
day18/module.py Normal file
View File

@@ -0,0 +1,125 @@
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 line.strip()
def p1():
inp = get_input(pw)
tot = []
for sample in inp:
stack = []
operand = ''
operator = ''
for i in sample[0:]:
if i == ' ':
continue
if i in list(map(str, range(10))):
operand = i
if operator == '':
res = int(operand)
elif operator == '+':
res += int(operand)
elif operator == '*':
res *= int(operand)
if i == '(':
stack.append((res, operator))
operator = ''
res = 0
elif i == ')':
value, operator = stack.pop()
if operator == '':
res = value
elif operator == '+':
res += value
elif operator == '*':
res *= value
else:
operator = i
tot.append(res)
res = 0
print(sum(tot))
return inp
def p2():
inp = get_input(pw)
rr = []
for sample in inp:
stack = []
operand = ''
operator = ''
#print(sample)
for i in sample[0:]:
if i == ' ':
continue
if i in list(map(str, range(10))):
operand = i
if operator == '':
res = int(operand)
elif operator == '+':
res += int(operand)
elif operator == '*':
res *= int(operand)
if i == '(':
stack.append((res, operator, '('))
operator = ''
res = 0
elif i == ')':
brace = ''
while brace != '(':
value, operator, brace = stack.pop()
if operator == '':
if value != 0:
res = value
elif operator == '+':
res += value
elif operator == '*':
res *= value
else:
operator = i
if operator == '*':
stack.append((res, operator, ''))
operator = ''
res = 0
#print(i, res, stack)
while(len(stack)>0):
#print(res, stack)
value, operator, brace = stack.pop()
if operator == '':
if value != 0:
res = value
elif operator == '+':
res += value
elif operator == '*':
res *= value
#print(res)
rr.append(res)
res = 0
print(sum(rr))
return 0
result1 = None
if part_one():
start = time.time()
result1 = p1()
print(round(1000*(time.time() - start), 2), 'ms')
if part_two():
start = time.time()
p2()
print(round(1000*(time.time() - start), 2), 'ms')

42
day21/data/data.txt Normal file
View File

@@ -0,0 +1,42 @@
mfp ncqls nnkrx mgvfmvp vjqr ncbrv jdfhh llkth xnmbjh dphvbt xzgcll hscht ngjt tljxbd nhdjth hcdchl nnsvvkz tlppq mpqvcfq csglnm dsghj kvxv mzpzjm klmr fjf mhnrqp vkkcf lkrf kzz vfrcj crrvj gnvrcr spzzmx dcvrf vmls xggzsks rzgsq gcpff xzzs mcg lfmfr ltvt nnpbm pbfjh pvnt zbrncpp dvkbjh zjzrkb vkxcxr (contains soy)
qbmcl vkkcf zxxhkv xzzs cfn ncbrv kxzdg lfmfr tljxbd ctjcbcls zjzrkb fxtrzm hcdchl bsmmc mhqhbm cjljfx hvcrh zvcf vpxc nnkrx bcjz sgrhdz smmnq tsptf ctqch bvvp qrxs grqvth dfzjk fkczp cr zzlvpcq rjlqxr ccxjnp ztpss jslzv hrdt kzz tjzhk llzlhc vshqdk ptlp qhjvlz nxhrrv bht vkxcxr mgvfmvp ddvbtk cmksdt mfglxb xggzsks rqddvr vpbhh kdt lvmm dvkbjh mhnrqp vjrzsrb nhdjth xzgcll crrvj jzqhqps jtll mfp (contains dairy, soy)
tsptf vpbhh kcfk hrdt dcszch tjzhk zxxhkv nhdjth zzkqgl kthcp dvkbjh vvn jbgmczs txztr sqfls kvxv dphvbt rlkrtn vkkcf mpqvcfq mfp zz gz hcdchl lkrf crrvj ngvl cgbj drg zsxbx spzzmx mfglxb vpbrd xvbvt lfmfr nnpbm qhjvlz nnrspld mgvfmvp nmvktj prds rzgsq ncbrv xjtkz vshqdk ddvbtk dcvrf qbmcl vzg fdq pbfjh qrxs vpj kgzs zzlvpcq xzzs mhnrqp mpjjc brvbdk (contains sesame, fish)
hcdchl ltvt mgvfmvp fxkz gnvrcr zxxhkv tsptf fdq trl kxzdg fgdtk fcsxn thtj mhnrqp fbnnl vkxcxr sqfls fnzgpkd snxph pbvx dcvrf ccxjnp cs gz mpjjc pszks lknqg ptlp jgqvpj vpbrd nhdjth zzlvpcq qhjvlz vmls kgst cr xvpcp bsmmc dsjkjjz smmnq nxhrrv vpxc rthfc mzpzjm vshqdk fcdgnm xzgcll dcszch grqvth mfp vkkcf jcth ghx drg cpgxmh vfrcj cvqmhtgg dvkbjh xjtkz zjzrkb ndmtbp mbcl dmxcb sgb klmr fkczp prds vpj vpbhh gcpff nnsvvkz lhv kdt pldq kgzs txztr (contains dairy, peanuts, fish)
vpj ztcm zzkqgl fnzgpkd qrxs sgb fbbxv mhnrqp dpzv bnmgsh cpgxmh dcvrf mfp gnvrcr dcszch vhdmkr kdt kthcp trl hppgd lvxvb dmxcb hcdchl nhdjth nxhrrv rlkrtn dqfdth tsptf zvcf dvkbjh pbfjh prds xggzsks fxkz thtj vpxc fkrf mpjjc bcjz kcfk fxtrzm snxph lhv jzqhqps vgmgvd fgdtk dsjkjjz mcg vjqr mbcl tchrfb llkth (contains dairy, peanuts)
lvxvb zvrqj dqfdth ctjcbcls dvkbjh gxc hppgd jgqvpj cfn vjqr bsmmc pbfjh tjzhk bcjz fdq vpbhh tljxbd mcg hscht ltvt ktvqj vshqdk nnkrx zvcf jbgmczs pszks cs crrvj fkrf qds vpj hcdchl rrjlqh tbbfh hgvst zsxbx lfmfr tsptf prds cmksdt xjtkz vkxcxr tp mgvfmvp tlppq mfp tchrfb cjljfx xzzs mhqhbm rjlqxr ndzjn fcsxn cgbj nhdjth ctqch xzgcll klmr tzgmld dcszch ptlp zmchhmf njpg nnsvvkz fkczp grqvth dcvrf zjzrkb pvnt sqfls xggzsks (contains dairy)
ztcm rrjlqh mbcl mpjjc vpj sgb jgqvpj vjqr llzlhc gxc dqfdth ndmtbp vhdmkr ltvt hgvst cs fxkz lfkp hcdchl cgbj lfmfr mgvfmvp cjljfx xdctcc dsjkjjz gz sgrhdz jtll ccxjnp kzz nkxsm dphvbt ctqch jcth xvpcp kgzs kkflzhh vfrcj fcdgnm bvjpl dcvrf dpzv bcjz lfjrzv ptlp kdt mfp rthfc fbnnl qds jslzv ctjcbcls tbbfh dvkbjh nhdjth lhv snxph mhqhbm hrdt kvxv fxtrzm txztr zjzrkb mfglxb fj vkkcf cvqmhtgg gnvrcr xnmbjh zbrncpp tmkfc ngjt zsxbx gcssxq xzgcll (contains shellfish)
jbgmczs tbbfh zvrqj kgzs tlppq bcjz fbbxv fcsxn drg mhnrqp kzz fbnnl thtj tlxs zxxhkv ztcm qds xvbvt pszks vshqdk fxtrzm bvjpl nsvbkbz vpbhh dfzjk xzzs tjzhk mpqvcfq nhdjth dcvrf fjf dvkbjh mbcl hscht cfn zsxbx hcdchl bht ndzjn fkczp tzgmld zzkqgl brvbdk hvcrh vjrzsrb mgvfmvp nnrspld pbvx ngvl ngjt fxkz rrjlqh gz cpgxmh ptlp qrxs nmvktj mzpzjm pvnt gcssxq lknqg (contains shellfish, nuts, peanuts)
smmnq sgrhdz vpbhh dpzv lhv fklh ndmtbp lfjrzv fbbxv zxxhkv tp cs vfrcj mgvfmvp zmchhmf cmksdt tjzhk ccmjg cr ngjt tsptf ptlp txztr mpjjc dvkbjh zvrqj hvcrh mfdnj qds klmr nxhrrv vvn dcszch pldq hcdchl msvjddz bht mfp xvbvt cvqmhtgg ztcm jcth ncbrv mhnrqp crrvj fnzgpkd zpvzrdc pszks kkflzhh dmxcb hgvst dsjkjjz sqfls nhdjth jdfhh bnmgsh dcvrf ccxjnp fxtrzm tlppq jgqvpj xdctcc ktvqj zsxbx jslzv zbgpfdc kzz skfc mpqvcfq mzpzjm kvxv znhgh mhqhbm gz xcv cjljfx lfmfr lfkp hrdt vjqr spzzmx mcg mbcl njpg (contains nuts, peanuts, sesame)
njpg vhdmkr fjf xzkpktr hv ztpss cmksdt cjljfx vvn pbfjh sgb ktvqj ndzjn lhv bvjpl qrxs dvkbjh vzg ctjcbcls xcv ccmjg znhgh nxhrrv nmvktj rjlqxr ddvbtk tmkfc msvjddz vpxc bcjz kxzdg mhnrqp fxkz cfn kkflzhh hcdchl xvpcp mzpzjm lfkp vpbrd hscht mfp gxc dcvrf prds nnpbm kthcp nnkrx fkrf nsvbkbz fdq mgvfmvp pldq hvcrh smmnq zzlvpcq lfmfr dcszch zbrncpp zsxbx tp lvmm sznfj jgqvpj vfrcj llzlhc tzgmld spzzmx kdt kgzs pbvx dsjkjjz skfc rlkrtn lkrf qhjvlz (contains sesame, nuts)
xzzs kcfk tlxs tjzhk nxhrrv lvxvb gz cvqmhtgg kzz txztr sgrhdz xdctcc ngjt ktvqj cjljfx xzgcll xzkpktr vpbrd zbgpfdc hcdchl ptlp gnvrcr mhnrqp bvvp fqrnx mbcl qbmcl zmchhmf ctjcbcls bcjz jslzv vkkcf skfc vjrzsrb jcth kxzdg mpqvcfq fbnnl zxxhkv sgb ddvbtk jdfhh dcvrf vvn jbgmczs vpj vmls nnpbm xcv tlppq llzlhc tp fgdtk kkflzhh fdq nhdjth grqvth mgvfmvp sqfls rjlqxr mfp khpx mzpzjm fnzgpkd (contains shellfish, nuts, sesame)
sgb jtll nnpbm bnmgsh zz mgvfmvp jslzv tbbfh fklh mcg zbrncpp xvpcp mfp cpgxmh hrdt drg dcvrf mhnrqp fbbxv dphvbt znhgh xzkpktr xzgcll dvkbjh xggzsks nxhrrv hcdchl ndzjn ptlp vshqdk rrjlqh hvcrh vmls fcdgnm ghx ctjcbcls ztcm bsmmc zzkqgl cgbj lfmfr rjlqxr cmksdt mbcl bcjz qhjvlz (contains soy)
tlxs dcvrf khpx trl cjljfx smmnq spzzmx tlppq prds ztcm tchrfb gnvrcr qrxs gcssxq kgst mgvfmvp pvnt sgb ndzjn mfp bvjpl cvqmhtgg sznfj mhnrqp tzgmld qds dmxcb dqfdth hv ccmjg vgmgvd fbnnl fxtrzm dpzv rjlqxr ngjt fcdgnm hcdchl tp fkrf mbcl ctqch csglnm zxxhkv nhdjth vpxc vmls ccxjnp pszks nxhrrv jtll bcjz (contains sesame)
nhdjth kgst vpbrd jslzv ztpss fjf dqfdth hv prds dpzv dcszch tlxs dcvrf zzkqgl dfzjk nnkrx bsmmc kthcp mgvfmvp txztr trl ngvl msvjddz zsxbx sgrhdz fkczp jdfhh hcdchl gnvrcr rlkrtn hvcrh csglnm bvvp ztcm fnzgpkd kcfk hscht rthfc kvxv lfmfr mbcl lknqg grqvth zvcf xvpcp pszks znhgh tp mhqhbm llzlhc nnsvvkz mpjjc zvrqj cfn smmnq ngjt gcssxq ndzjn fgdtk nnrspld rzgsq bcjz nmrbb nsvbkbz mfp ncqls spzzmx mhnrqp cgbj lvxvb ncbrv xdctcc rqddvr lfkp ccxjnp vjqr (contains nuts, shellfish)
cgbj mbcl jgqvpj thtj cvqmhtgg ncqls lfjrzv jbgmczs fbnnl drg zmchhmf vmls rrjlqh sznfj rjlqxr tljxbd vzg nnsvvkz fklh jzqhqps fbbxv tbbfh qhjvlz cjljfx sqfls ltvt fj hgvst hrdt mfp bsmmc vpbrd grqvth tlxs nhdjth ccxjnp pvnt tzgmld vpxc dcvrf tsptf lfkp xzgcll fdq hcdchl hppgd sgrhdz kvxv vvn nmvktj llzlhc nnrspld dvkbjh dfzjk zpvzrdc ncbrv zjzrkb ktvqj xvpcp ngjt kcfk kzz lvmm sgb bvjpl kdt fjf mhnrqp mpqvcfq bcjz crrvj (contains fish, sesame, dairy)
fkrf nsvbkbz fj vkxcxr kgzs mhnrqp ccmjg ztpss gcpff bcjz vpbrd dmxcb fcdgnm nhdjth ngjt gnvrcr snxph lkrf khpx brvbdk lfmfr jzqhqps msvjddz ccxjnp zbrncpp mfglxb cmksdt rthfc skfc vfrcj tmkfc mbcl hcdchl kgst ptlp dqfdth vpxc zvrqj sgrhdz mfp dcvrf fxtrzm kzz gcssxq dsjkjjz bnmgsh rlkrtn dvkbjh fklh znhgh dcszch ddvbtk smmnq qrxs fxkz nnsvvkz qhjvlz nkxsm mzpzjm vpbhh fbnnl jslzv vgmgvd cgbj cvqmhtgg fgdtk nmrbb tbbfh ndzjn ncbrv (contains fish)
lkrf fklh vgmgvd cmksdt kthcp kdt zbrncpp ztcm njpg crrvj kgst tp znhgh mhnrqp zzkqgl mfp gnvrcr gcpff vfrcj dpzv zbgpfdc rjlqxr vmls dmxcb lvxvb dqfdth bcjz cpgxmh rrjlqh llkth dvkbjh tljxbd dsjkjjz xnmbjh trl ddvbtk lfjrzv nhdjth mhqhbm cs xvpcp fgdtk hvcrh hcdchl vpxc lknqg sgb mpqvcfq pldq sqfls zz ghx nkxsm jzqhqps cr fxkz fnzgpkd thtj lvmm zmchhmf hgvst jtll zvrqj gz tchrfb tjzhk jgqvpj zpvzrdc dcvrf jcth (contains dairy, shellfish)
cjljfx hvcrh nnsvvkz thtj smmnq tlxs tp kgst hcdchl zz fklh csglnm lfkp lknqg llzlhc zjzrkb lfjrzv zbgpfdc mhqhbm ncbrv lvmm rthfc gnvrcr brvbdk kxzdg xzgcll nnkrx ztcm vkkcf ndmtbp lvxvb zxxhkv grqvth vfrcj ccxjnp mhnrqp vjrzsrb fxtrzm ccmjg nnrspld mfp trl fnzgpkd vpj jdfhh bvjpl cmksdt bvvp njpg znhgh dpzv qds xcv cvqmhtgg zvrqj zvcf fbbxv qrxs mbcl bcjz nhdjth tbbfh ncqls cr zpvzrdc vvn xzzs nsglr cpgxmh mgvfmvp dqfdth dcszch zmchhmf zsxbx hrdt nmvktj lfmfr kvxv vhdmkr tzgmld mfglxb hv fxkz xnmbjh rjlqxr skfc mfdnj dcvrf pbfjh ndzjn rqddvr zzlvpcq (contains dairy, sesame)
zbrncpp ccmjg mhnrqp zvcf ncqls khpx jdfhh fkrf jbgmczs hppgd dcvrf hvcrh dqfdth znhgh zxxhkv xnmbjh zvrqj kthcp lfmfr csglnm pvnt mfdnj grqvth ptlp dvkbjh mbcl ddvbtk skfc mhqhbm dfzjk mpjjc bvjpl mfp lvmm vgmgvd lfkp kdt fgdtk fqrnx fbbxv nnrspld jtll tlxs prds nhdjth kgst bcjz gnvrcr xzzs lfjrzv kgzs rrjlqh hcdchl xjtkz qrxs lvxvb (contains nuts, dairy)
pbfjh crrvj dvkbjh dmxcb dcvrf nnsvvkz fcsxn jslzv nnkrx dpzv kkflzhh fnzgpkd tchrfb xzgcll njpg nhdjth xjtkz dphvbt cvqmhtgg mhnrqp zzkqgl kdt ddvbtk nmvktj ghx mcg xzzs cr cjljfx bsmmc kgst dsjkjjz fjf rlkrtn snxph hcdchl vkxcxr xvpcp fqrnx tzgmld trl mpjjc lvmm ndzjn rthfc pbvx vzg ltvt zz vfrcj bcjz ctjcbcls nnpbm prds vvn vshqdk hv rjlqxr nkxsm fbnnl qrxs qhjvlz tsptf tmkfc lfjrzv vpbrd pvnt drg vkkcf kcfk fbbxv hvcrh zsxbx ndmtbp sznfj mfdnj mhqhbm ncqls llkth mgvfmvp jdfhh rqddvr jcth cmksdt (contains shellfish, sesame, nuts)
cr sqfls gcssxq nnkrx vkkcf tlppq lkrf hrdt ltvt ddvbtk ptlp mpjjc zpvzrdc rlkrtn nkxsm nnpbm hgvst tchrfb ctqch vjrzsrb xzzs pbvx jzqhqps dcvrf nhdjth zbrncpp xzgcll zvcf hcdchl dvkbjh msvjddz tljxbd nsvbkbz sznfj fxkz bvvp ktvqj sgb vpj kdt dcszch rjlqxr ncbrv lfjrzv snxph ctjcbcls ccxjnp prds ngvl dpzv zzkqgl bcjz mfp lhv ztcm spzzmx mhnrqp jbgmczs znhgh thtj llzlhc cfn lvxvb fjf cpgxmh dsjkjjz vpxc jdfhh fklh mfglxb cvqmhtgg kkflzhh fxtrzm gxc vzg dqfdth lfmfr vvn rqddvr qrxs hscht xjtkz cjljfx zjzrkb fgdtk gcpff fqrnx tsptf (contains soy, nuts)
tlxs mhnrqp mfp hscht trl rlkrtn xzgcll bcjz ncqls fj nmrbb zsxbx vzg mpjjc lknqg tljxbd jzqhqps jbgmczs skfc kvxv fcdgnm nsvbkbz zzlvpcq nnsvvkz nhdjth vgmgvd ccmjg ddvbtk bvvp nnpbm cfn ctqch nnkrx lfjrzv vpj kgst kgzs hgvst sgb bvjpl kkflzhh fbbxv rqddvr hcdchl mgvfmvp kdt fgdtk fxtrzm vvn fqrnx nxhrrv brvbdk bsmmc tmkfc cgbj smmnq vkxcxr ztpss kzz rthfc spzzmx mfglxb msvjddz dcvrf jcth sqfls vpxc hvcrh (contains sesame, shellfish, nuts)
nnsvvkz nsvbkbz vshqdk csglnm fcsxn zzkqgl ncqls ncbrv fklh tlppq kdt vkxcxr lvmm fdq pbfjh gz jgqvpj ndmtbp cpgxmh llkth bnmgsh ctqch zvcf nhdjth mhqhbm tzgmld xjtkz nxhrrv vhdmkr nnpbm fxtrzm hscht vpbrd zvrqj bvvp lfjrzv tchrfb ngvl qhjvlz tmkfc grqvth vmls dcvrf dvkbjh bsmmc fj bcjz hcdchl vjrzsrb cjljfx tbbfh kcfk ctjcbcls mpqvcfq mpjjc dpzv snxph dcszch mfp nkxsm mzpzjm thtj lkrf pvnt rthfc qds lhv llzlhc cmksdt zbgpfdc hgvst mhnrqp jtll ktvqj zmchhmf (contains dairy, nuts, sesame)
zzlvpcq ccxjnp kdt ncbrv ngvl brvbdk vzg dcvrf vvn dfzjk sgb skfc hscht nmvktj kxzdg mfp kthcp mgvfmvp ltvt jbgmczs pldq kzz vfrcj dvkbjh mhnrqp hgvst ndmtbp vmls fqrnx bcjz vkkcf cmksdt thtj zvrqj ngjt bht klmr rzgsq vpbrd zz khpx hcdchl zxxhkv ztpss kcfk (contains sesame, peanuts, dairy)
fdq cpgxmh tlxs xzzs dpzv zxxhkv drg nnpbm lfmfr grqvth tchrfb gxc mfglxb fj zvcf zpvzrdc vshqdk cjljfx skfc vpxc pvnt mhnrqp xnmbjh nmvktj fbbxv pszks dcvrf nhdjth hvcrh gnvrcr fnzgpkd ndzjn cs xjtkz bcjz nxhrrv tljxbd mgvfmvp zjzrkb qds fcsxn rzgsq vpj dvkbjh lkrf zsxbx ccmjg vpbrd ltvt lvxvb bnmgsh ncqls fxtrzm hscht msvjddz mfp fqrnx ndmtbp njpg (contains soy)
sgb tjzhk trl gnvrcr rlkrtn pvnt bcjz mfp bht dsjkjjz ztpss bvjpl qhjvlz ltvt rqddvr xcv lvmm mgvfmvp lhv sgrhdz rjlqxr mhqhbm ngjt nhdjth fj llkth fxtrzm lvxvb xvbvt ktvqj vfrcj ngvl grqvth thtj prds pbvx mcg kcfk gcssxq brvbdk hv dvkbjh pldq ndzjn cjljfx fcdgnm dcvrf fkczp zsxbx xjtkz kthcp xzgcll ncqls nsglr jdfhh vshqdk mhnrqp snxph vvn tchrfb (contains shellfish, soy)
vzg jcth dsghj cr nnpbm sgb snxph cs tmkfc msvjddz mbcl znhgh vshqdk cmksdt kgst mgvfmvp cvqmhtgg fj hcdchl nhdjth pldq zjzrkb ccmjg fklh ptlp tbbfh dvkbjh vpbrd fkczp trl kvxv dsjkjjz grqvth drg dfzjk gnvrcr qbmcl vjqr lfkp jzqhqps hppgd khpx lfjrzv mfdnj vpj mhnrqp qds xcv kkflzhh bcjz klmr nxhrrv tzgmld bsmmc xzkpktr pbvx dcvrf vkxcxr sgrhdz jtll vgmgvd xzgcll ndmtbp gcssxq ndzjn fxkz gcpff jbgmczs ngjt pvnt mpjjc fdq nnrspld tp nmrbb sqfls lvxvb zxxhkv ctjcbcls lkrf (contains soy, nuts, sesame)
ktvqj gxc kdt grqvth pbvx mfglxb ndzjn xzkpktr nhdjth ccxjnp njpg rzgsq ncqls hcdchl fbnnl ccmjg sqfls ltvt dsghj vpxc zbrncpp dvkbjh mfdnj xjtkz mhnrqp ngvl xvbvt qbmcl mgvfmvp fxkz dsjkjjz znhgh jbgmczs ncbrv dcvrf mhqhbm lkrf mcg hppgd tchrfb gcssxq fxtrzm bcjz vfrcj rthfc zpvzrdc tp hscht nnkrx (contains sesame, peanuts, fish)
dvkbjh gcssxq vzg bvjpl nhdjth fxtrzm kzz vmls vvn kgst dfzjk dsghj vpbhh tsptf snxph ltvt vpbrd ngvl cjljfx ndmtbp znhgh fqrnx fbnnl mfglxb xzzs hcdchl gcpff mhnrqp tp hrdt nnsvvkz ccmjg zxxhkv dcvrf klmr mgvfmvp lkrf ndzjn dphvbt hppgd jtll nsglr mfp fxkz mpjjc fcdgnm (contains peanuts)
fxkz mfp ptlp rjlqxr njpg mgvfmvp dcszch dcvrf zzlvpcq hgvst xdctcc fkczp gxc dfzjk crrvj ngjt sznfj dvkbjh fkrf ktvqj jbgmczs bsmmc cr pvnt lkrf gnvrcr ztcm mhnrqp vpbrd bcjz rthfc kdt mpjjc bht skfc xjtkz dsghj zmchhmf ndzjn tmkfc zpvzrdc nhdjth brvbdk vgmgvd jzqhqps (contains eggs, peanuts)
prds hv mhnrqp msvjddz ncqls xzkpktr vpj vgmgvd thtj ccxjnp hcdchl klmr nkxsm zmchhmf spzzmx nhdjth cjljfx nmrbb vkxcxr nnsvvkz tsptf mfp gcssxq zvcf mfglxb ctqch vpbrd qrxs kzz bcjz gz zjzrkb njpg nxhrrv hrdt sgrhdz mgvfmvp fgdtk nsvbkbz dvkbjh fkrf kgst tmkfc mfdnj ccmjg fxtrzm dqfdth mbcl jbgmczs jslzv jdfhh vvn crrvj mpqvcfq pbvx pvnt hppgd vzg fxkz tp zz xdctcc rthfc smmnq dsjkjjz vpxc rqddvr rlkrtn dcszch cvqmhtgg hgvst sgb fj lfkp (contains fish)
zzkqgl hscht vzg lfkp xnmbjh gz ptlp cs thtj jslzv hcdchl tlxs mhnrqp sqfls dphvbt mfp llzlhc kkflzhh hv kcfk dcvrf bht rthfc jzqhqps mgvfmvp cjljfx pbfjh smmnq zmchhmf jgqvpj dvkbjh ltvt cgbj cr dfzjk khpx nnkrx njpg jdfhh tjzhk nhdjth xdctcc ccmjg jcth cmksdt lknqg bsmmc kdt kxzdg xzkpktr rlkrtn msvjddz hvcrh xvbvt ddvbtk zsxbx gcssxq vmls qbmcl zzlvpcq vpxc kgst nsvbkbz skfc znhgh vjqr bnmgsh zjzrkb ktvqj dpzv nxhrrv vkxcxr pszks (contains nuts, peanuts, eggs)
rqddvr kxzdg fxkz nmvktj cs zvrqj dvkbjh qrxs vgmgvd nnrspld nhdjth bcjz fkczp hcdchl khpx cmksdt bnmgsh fcsxn xzgcll ndmtbp xzkpktr ncqls mhnrqp ltvt fjf ghx vkkcf lkrf dsghj cvqmhtgg ndzjn xcv mzpzjm mgvfmvp crrvj fnzgpkd kthcp bvvp spzzmx nxhrrv mfp drg skfc cjljfx (contains eggs)
tzgmld vkxcxr jdfhh ngvl kvxv llkth ghx skfc sqfls ndmtbp gz cvqmhtgg fnzgpkd ptlp pvnt zmchhmf zbgpfdc tmkfc xvbvt nsvbkbz ccmjg mfglxb msvjddz pszks jgqvpj fj nhdjth nnrspld zbrncpp mfp xdctcc kdt cs ctjcbcls kcfk dvkbjh fjf snxph nkxsm dfzjk dcvrf bcjz dpzv rrjlqh cmksdt nmrbb vgmgvd qbmcl xzgcll bvvp cgbj csglnm mhnrqp prds dsghj zzkqgl xggzsks fkczp hcdchl ndzjn nmvktj fkrf (contains peanuts, fish)
tmkfc nhdjth mfp hcdchl ncbrv lhv pbfjh fjf kkflzhh kvxv mhnrqp hrdt sgrhdz fklh fdq tzgmld mfdnj pvnt grqvth vvn nnkrx vmls mgvfmvp brvbdk klmr drg pszks ndmtbp zjzrkb cgbj bvjpl kcfk zxxhkv zz cmksdt qrxs khpx xcv dsghj tlppq fbbxv fxtrzm ddvbtk znhgh mfglxb tchrfb ccxjnp jdfhh dvkbjh zzkqgl spzzmx nsglr qds cr zmchhmf ktvqj zbrncpp dcszch jslzv fgdtk vkkcf rjlqxr ngjt tsptf fcsxn vjqr lfmfr nsvbkbz dphvbt xnmbjh bcjz jcth fnzgpkd hscht xvbvt mzpzjm hvcrh (contains peanuts, nuts, shellfish)
ltvt rrjlqh hscht dcvrf mfglxb qrxs mpjjc tjzhk hvcrh ptlp prds xzzs kgst gz mhqhbm skfc crrvj lvxvb mhnrqp jcth dvkbjh nxhrrv nnkrx fkrf hrdt fbnnl mfp lknqg qds zvcf hgvst tljxbd zjzrkb lfkp xvpcp jgqvpj pldq bcjz vshqdk vvn zmchhmf fjf hcdchl fklh zz mgvfmvp (contains nuts, sesame)
zvcf dvkbjh hscht qds lvmm pbfjh msvjddz kgzs sgb nsvbkbz rzgsq jtll fklh xvpcp pvnt mfp zvrqj mgvfmvp fxkz mzpzjm ktvqj zpvzrdc kgst tbbfh mfdnj zmchhmf hcdchl qrxs lfmfr vpbrd lvxvb rlkrtn rthfc nhdjth pbvx dcvrf znhgh dsjkjjz thtj spzzmx gz nmrbb tljxbd dmxcb ncbrv vvn zsxbx hv ddvbtk ptlp bsmmc lfkp sgrhdz xggzsks kkflzhh bcjz fcsxn fxtrzm lknqg (contains fish, shellfish)
vjrzsrb mfp cvqmhtgg gcpff nhdjth tchrfb lfkp ngjt pbvx vshqdk nnkrx ncqls kvxv xnmbjh ctjcbcls grqvth nnpbm vgmgvd nnrspld bcjz snxph pbfjh zzlvpcq dmxcb gnvrcr crrvj sgrhdz thtj xzzs mbcl tjzhk cmksdt zvrqj mgvfmvp tlxs dcvrf zz tp dpzv ncbrv mhnrqp vkxcxr zbrncpp ndzjn hcdchl pvnt lfjrzv bvvp (contains soy, eggs)
bsmmc hgvst bcjz nnpbm dfzjk hscht zzkqgl vshqdk mfp mhnrqp xvbvt dvkbjh kvxv jdfhh fkczp rthfc tsptf mgvfmvp hcdchl rzgsq ngjt tjzhk bvjpl nnrspld ztcm fqrnx mbcl tzgmld xggzsks crrvj zzlvpcq nnkrx dsjkjjz tchrfb zjzrkb mfdnj ztpss kkflzhh ccmjg lvmm tlxs qhjvlz lkrf vpxc vmls khpx jbgmczs vhdmkr fkrf vfrcj nsglr fbbxv ctjcbcls vpj fcsxn xnmbjh mpqvcfq ctqch mpjjc nhdjth sgrhdz mcg vpbrd smmnq tljxbd ndzjn zbrncpp zvcf lfmfr vjqr gcpff skfc (contains nuts, soy)
ngvl crrvj hppgd tlxs ztcm rqddvr njpg vkxcxr xzgcll vpbhh cs mhqhbm vkkcf nmvktj fj dvkbjh ztpss ndzjn rjlqxr mgvfmvp tljxbd prds fbbxv mpqvcfq nnkrx sgb mfp kgst brvbdk hcdchl mhnrqp gz tjzhk fnzgpkd fkrf kcfk zz tsptf bht cvqmhtgg ddvbtk nkxsm zvcf xvbvt sqfls klmr fjf msvjddz zzkqgl qds txztr dcvrf vjqr jslzv xnmbjh qbmcl thtj rlkrtn qrxs vvn jdfhh lkrf cjljfx xzkpktr nxhrrv nnrspld nnsvvkz nsvbkbz llkth pldq fxkz kdt xzzs kxzdg kzz bvvp nhdjth lknqg pbvx (contains nuts)
ncqls vgmgvd xcv hgvst mhnrqp trl spzzmx ctqch fdq mbcl grqvth vpbrd tljxbd xzkpktr lfmfr nxhrrv ctjcbcls bsmmc pbvx kdt fkrf ktvqj vpxc vmls nnsvvkz tjzhk pszks tp ngjt lfkp qhjvlz zvcf dphvbt znhgh kzz zzkqgl ngvl txztr mgvfmvp sqfls xggzsks qds cvqmhtgg bvjpl hcdchl ghx tzgmld xvpcp dcvrf mpqvcfq mfp nhdjth cs njpg lvxvb bcjz khpx lkrf lvmm (contains fish)
sgb mgvfmvp bvvp nxhrrv qbmcl cpgxmh kzz mpqvcfq zvrqj bsmmc kxzdg ncqls fcdgnm vzg cgbj gz hcdchl gnvrcr lfkp mfdnj mbcl lknqg fkczp spzzmx dcvrf jgqvpj txztr bcjz brvbdk gcssxq sznfj pbfjh qds fklh mfp msvjddz tmkfc mcg pldq njpg mhnrqp ctqch dvkbjh nnkrx dpzv hvcrh tlppq snxph zzlvpcq ndzjn (contains dairy, nuts)

4
day21/data/sample.txt Normal file
View File

@@ -0,0 +1,4 @@
mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
trh fvjkl sbzzf mxmxvkd (contains dairy)
sqjhc fvjkl (contains soy)
sqjhc mxmxvkd sbzzf (contains fish)

1
day21/index.html Normal file
View File

@@ -0,0 +1 @@
404 Not Found

81
day21/module.py Normal file
View File

@@ -0,0 +1,81 @@
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 line.strip()
def p1():
inp = get_input(pw)
lst = []
ingredients = set()
lingredients = []
idict = collections.defaultdict(list)
for sample in inp:
i, a = sample.split('(contains ')
a = a[:-1].strip()
lst.append((i.strip().split(' '), a.split(', ')))
is_ = i.strip().split(' ')
lingredients.extend(is_)
for x in is_:
ingredients.add(x)
for a2 in a.split(', '):
idict[a2].append(is_)
allergens = set()
hazzard = collections.defaultdict(list)
for allergen, t in idict.items():
v = set(t[0])
for tt in t[1:]:
v = v.intersection(tt)
for x in v:
allergens.add(x)
for x in v:
hazzard[x].append(allergen)
count = 0
for l in lingredients:
if l not in allergens:
count += 1
print(count)
return hazzard
def p2(hazzard):
while any(map(lambda x: len(x)>1, hazzard.values())):
hazzard2 = {}
for i, a in hazzard.items():
for a2 in filter(lambda x: len(x) == 1, hazzard.values()):
if a == a2:
continue
v = set(a).symmetric_difference(a2) & set(a)
if len(v) <= len(hazzard[i]) and len(v) > 0:
if i in hazzard2:
hazzard2[i] = list(v.intersection(hazzard2[i]))
else:
hazzard2[i] = list(v)
if i not in hazzard2:
hazzard2[i] = hazzard[i]
hazzard = hazzard2
print(','.join([x[0] for x in sorted(hazzard.items(), key=lambda x: x[1])]))
return 0
result1 = None
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')

54
day22/data/data.txt Normal file
View File

@@ -0,0 +1,54 @@
Player 1:
1
10
28
29
13
11
35
7
43
8
30
25
4
5
17
32
22
39
50
46
16
26
45
38
21
Player 2:
19
40
2
12
49
23
34
47
9
14
20
24
42
37
48
44
27
6
33
18
15
3
36
41
31

14
day22/data/sample.txt Normal file
View File

@@ -0,0 +1,14 @@
Player 1:
9
2
6
3
1
Player 2:
5
8
4
7
10

1
day22/index.html Normal file
View File

@@ -0,0 +1 @@
404 Not Found

134
day22/module.py Normal file
View File

@@ -0,0 +1,134 @@
from aoc.input import get_input
import time
import copy
import itertools
import time
import collections
import re
from aoc.partselector import part_one, part_two
import functools
def pw(line):
return line.strip()
def p1():
inp = get_input(pw)
players = []
temp = []
for sample in inp:
if sample == '':
players.append(temp)
temp = []
continue
if not 'Player' in sample:
temp.append(int(sample))
while True:
i = (players[0].pop(0), players[1].pop(0))
print(i)
if i[0] > i[1]:
players[0].append(i[0])
players[0].append(i[1])
else:
players[1].append(i[1])
players[1].append(i[0])
if(len(players[0]) == 0):
break
if(len(players[1]) == 0):
break
if len(players[0]) == 0:
w = players[1]
else:
w = players[0]
su = 0
for i, x in enumerate(reversed(w), start=1):
print(i,x)
su += i*x
print(su)
return inp
globalgame = 0
mdepth = 0
def p2():
inp = get_input(pw)
players = []
temp = []
for sample in inp:
if sample == '':
players.append(temp)
temp = []
continue
if not 'Player' in sample:
temp.append(int(sample))
print(players)
final = False
wins = [0, 0]
def play(players, depth=0):
global globalgame
global mdepth
mdepth = max(mdepth, depth)
globalgame += 1
history = set()
while all(filter(lambda x: len(x) > 0, players)):
hv = frozenset([frozenset(players[0]), frozenset(players[1])])
# ','.join(map(str, players[0])) + ':' + ','.join(map(str, players[1]))
if hv in history:
return 0
else:
history.add(hv)
i = (players[0].pop(0), players[1].pop(0))
if i[0] <= len(players[0]) and i[1] <= len(players[1]):
players2 = [players[0][:i[0]], players[1][:i[1]]]
won = play(players2, depth + 1)
if won == 1:
won = 0
else:
won = 1
#print(f'cont game {game} {won}')
else:
won = i[0] > i[1]
if won:
players[0].append(i[0])
players[0].append(i[1])
else:
players[1].append(i[1])
players[1].append(i[0])
if(len(players[0]) == 0):
return 1
if(len(players[1]) == 0):
return 0
won = play(players, 1)
if len(players[0]) == 0:
w = players[1]
else:
w = players[0]
su = 0
for i, x in enumerate(reversed(w), start=1):
#print(i,x)
su += i*x
print(su, f'(played games {globalgame}/{mdepth})')
return 0
result1 = None
if part_one():
start = time.time()
result1 = p1()
print(round(1000*(time.time() - start), 2), 'ms')
if part_two():
start = time.time()
p2()
print(round(1000*(time.time() - start), 2), 'ms')

1
day23/data/data.txt Normal file
View File

@@ -0,0 +1 @@
962713854

1
day23/data/sample.txt Normal file
View File

@@ -0,0 +1 @@
389125467

1
day23/index.html Normal file
View File

@@ -0,0 +1 @@
404 Not Found

122
day23/module.py Normal file
View File

@@ -0,0 +1,122 @@
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 line.strip()
def p1():
inp = get_input(pw)
cups = []
for sample in inp:
print(sample)
cups.append(int(sample))
def domove(cups, current):
current = current % len(cups)
selected = (cups+cups)[current+1:current+4]
selected_index = sorted([(current+1)%len(cups), (current+2)%len(cups), (current+3)%len(cups)], reverse=True)
print(cups)
origcurrent = cups[current]
targetid = cups[current] - 1
print(current, cups[current], selected, targetid)
for c in selected_index:
cups.pop(c)
target = None
if targetid == 0:
targetid = 9
while target == None:
try:
target = cups.index(targetid)
except:
targetid = (targetid - 1)
print('-', targetid)
if targetid == 0:
targetid = 9
if targetid < -1:
break
print('-', targetid)
print('destination', targetid, target, cups)
cups.insert(target + 1, selected[-1])
cups.insert(target + 1, selected[-2])
cups.insert(target + 1, selected[-3])
while not cups[current] == origcurrent:
cups = cups[1:] + cups[0:1]
print(cups)
return cups
current = 0
for i in range(5):
cups = domove(cups, current)
current += 1
cups = cups
cupss = ''.join(map(str,cups))
print(cupss)
a, b = cupss.split('1')
print(b + a)
return inp
def p2():
inp = get_input(pw)
cups = collections.deque()
for sample in inp:
cups.append(int(sample))
total = 1_000_000
for cc in range(10, 1_000_000+1):
cups.append(cc)
backup = collections.defaultdict(list)
def fixnext():
next_ = cups.popleft()
# ok, now is the time to put these values back
if next_ in backup:
cups.extendleft(reversed(backup[next_]))
del backup[next_]
return next_
def domove():
current = fixnext()
selected = [fixnext(), fixnext(), fixnext()]
unavailable = set([0, current] + selected)
# find dest
target = current - 1
while target in set(unavailable):
target -= 1
if target < 1:
target = total
backup[target] += selected
cups.append(current)
for _ in range(10_000_000):
domove()
while (next_ := fixnext()) != 1:
cups.append(next_)
a, b = fixnext(), fixnext()
print(a*b)
return inp
result1 = None
if part_one():
start = time.time()
result1 = p1()
print(round(1000*(time.time() - start), 2), 'ms')
if part_two():
start = time.time()
p2()
print(round(1000*(time.time() - start), 2), 'ms')

599
day24/data/data.txt Normal file

File diff suppressed because it is too large Load Diff

20
day24/data/sample.txt Normal file
View File

@@ -0,0 +1,20 @@
sesenwnenenewseeswwswswwnenewsewsw
neeenesenwnwwswnenewnwwsewnenwseswesw
seswneswswsenwwnwse
nwnwneseeswswnenewneswwnewseswneseene
swweswneswnenwsewnwneneseenw
eesenwseswswnenwswnwnwsewwnwsene
sewnenenenesenwsewnenwwwse
wenwwweseeeweswwwnwwe
wsweesenenewnwwnwsenewsenwwsesesenwne
neeswseenwwswnwswswnw
nenwswwsewswnenenewsenwsenwnesesenew
enewnwewneswsewnwswenweswnenwsenwsw
sweneswneswneneenwnewenewwneswswnese
swwesenesewenwneswnwwneseswwne
enesenwswwswneneswsenwnewswseenwsese
wnwnesenesenenwwnenwsewesewsesesew
nenewswnwewswnenesenwnesewesw
eneswnwswnwsenenwnwnwwseeswneewsenese
neswnwewnwnwseenwseesewsenwsweewe
wseweeenwnesenwwwswnew

1
day24/index.html Normal file
View File

@@ -0,0 +1 @@
404 Not Found

153
day24/module.py Normal file
View File

@@ -0,0 +1,153 @@
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 line.strip()
def p1():
inp = get_input(pw)
directions = {
# e,w 101
# ne, sw 101
# 101
"e": [1,0,-1],
"w": [-1,0,1],
"nw": [0,-1,1],
"se": [0,1,-1],
"ne": [1,-1,0],
"sw": [-1,1,0],
}
i2 = []
for sample in inp:
cnt = 0
steps = []
while cnt < len(sample):
if sample[cnt] in directions:
steps.append(directions[sample[cnt]])
cnt += 1
elif sample[cnt:cnt+2] in directions:
steps.append(directions[sample[cnt:cnt+2]])
cnt += 2
i2.append(steps)
b = collections.defaultdict(lambda: 0)
for n in i2:
c = [0,0,0]
for s in n:
c[0] += s[0]
c[1] += s[1]
c[2] += s[2]
print(c)
b[tuple(c)] += 1
count = 0
for x in b.values():
if x%2 == 1:
count += 1
print(count)
return inp
def p2():
inp = get_input(pw)
directions = {
# e,w 101
# ne, sw 101
# 101
"e": tuple([1,0,-1]),
"w": tuple([-1,0,1]),
"nw": tuple([0,-1,1]),
"se": tuple([0,1,-1]),
"ne": tuple([1,-1,0]),
"sw": tuple([-1,1,0]),
}
i2 = []
for sample in inp:
cnt = 0
steps = []
while cnt < len(sample):
if sample[cnt] in directions:
steps.append(directions[sample[cnt]])
cnt += 1
elif sample[cnt:cnt+2] in directions:
steps.append(directions[sample[cnt:cnt+2]])
cnt += 2
i2.append(steps)
b = collections.defaultdict(lambda: 0)
for n in i2:
c = [0,0,0]
for s in n:
c[0] += s[0]
c[1] += s[1]
c[2] += s[2]
b[tuple(c)] = (b[tuple(c)]+1)%2
count = 0
for x in b.values():
if x%2 == 1:
count += 1
print(count)
minx = min(map(lambda x: x[0], b.keys()))
maxx = max(map(lambda x: x[0], b.keys()))
miny = min(map(lambda x: x[1], b.keys()))
maxy = max(map(lambda x: x[1], b.keys()))
minz = min(map(lambda x: x[2], b.keys()))
maxz = max(map(lambda x: x[2], b.keys()))
def iterate2():
b2 = collections.defaultdict(lambda: 0)
for oc,v in b.items():
x,y,z = oc
if v == 1:
for s in directions.values():
c = tuple([x+s[0], y+s[1], z+s[2]])
b2[c] += 1
for c, x in b2.items():
if x == 2 and b[c] == 0:
b[c] = 1
elif (x == 0 or x > 2) and b[c] == 1:
b[c] = 0
for i in range(100):
iterate2()
count = 0
for x in b.values():
if x%2 == 1:
count += 1
print(i+1, count)
break
count = 0
for x in b.values():
if x%2 == 1:
count += 1
print(count)
return 0
result1 = None
if part_one():
start = time.time()
result1 = p1()
print(round(1000*(time.time() - start), 2), 'ms')
if part_two():
start = time.time()
p2()
print(round(1000*(time.time() - start), 2), 'ms')

36
module.py Normal file
View File

@@ -0,0 +1,36 @@
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 line.strip()
def p1():
inp = get_input(pw)
for sample in inp:
print(sample)
return inp
def p2(segments):
print(len(segments))
return 0
result1 = None
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')

20
open.sh
View File

@@ -2,8 +2,26 @@
day=$(date +'%-d') day=$(date +'%-d')
day0=$(date +'%d') day0=$(date +'%d')
time=$(date +'%H')
# /usr/bin/open https://adventofcode.com/2020/day/$day/input # /usr/bin/open https://adventofcode.com/2020/day/$day/input
mkdir -p day$day0/data/
cp module.py day$day0/
touch day$day0/data/sample.txt
current_epoch=$(date +%s)
if [ $time -gt 6 ]; then
day0=$(( $day0 + 1 ))
fi
target_epoch=$(date -j "12${day0}06002020.00" +%s)
sleep_seconds=$(( $target_epoch - $current_epoch +1))
echo "Sleep for $sleep_seconds"
sleep $sleep_seconds
day=$(date +'%-d')
day0=$(date +'%d')
curl -b cookies.txt https://adventofcode.com/2020/day/$day/input -o day$day0/data/data.txt curl -b cookies.txt https://adventofcode.com/2020/day/$day/input -o day$day0/data/data.txt
curl -b cookies.txt https://adventofcode.com/2020/day/$day -o day$day0/index.html curl -b cookies.txt https://adventofcode.com/2020/day/$day/ -o day$day0/index.html
cat day$day0/data/data.txt