day01+02
This commit is contained in:
200
day01/data/data.txt
Normal file
200
day01/data/data.txt
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
1078
|
||||||
|
1109
|
||||||
|
1702
|
||||||
|
1293
|
||||||
|
1541
|
||||||
|
1422
|
||||||
|
1679
|
||||||
|
1891
|
||||||
|
1898
|
||||||
|
1455
|
||||||
|
1540
|
||||||
|
1205
|
||||||
|
1971
|
||||||
|
1582
|
||||||
|
1139
|
||||||
|
1438
|
||||||
|
1457
|
||||||
|
1725
|
||||||
|
1907
|
||||||
|
1872
|
||||||
|
1101
|
||||||
|
1403
|
||||||
|
1557
|
||||||
|
1597
|
||||||
|
1619
|
||||||
|
1974
|
||||||
|
1287
|
||||||
|
292
|
||||||
|
1647
|
||||||
|
1444
|
||||||
|
1241
|
||||||
|
879
|
||||||
|
1761
|
||||||
|
1067
|
||||||
|
1178
|
||||||
|
1510
|
||||||
|
1110
|
||||||
|
1233
|
||||||
|
1121
|
||||||
|
1299
|
||||||
|
1796
|
||||||
|
1124
|
||||||
|
1768
|
||||||
|
1466
|
||||||
|
1871
|
||||||
|
1279
|
||||||
|
1344
|
||||||
|
1485
|
||||||
|
1258
|
||||||
|
1179
|
||||||
|
1147
|
||||||
|
492
|
||||||
|
1234
|
||||||
|
1843
|
||||||
|
1421
|
||||||
|
1819
|
||||||
|
1964
|
||||||
|
1671
|
||||||
|
1793
|
||||||
|
1302
|
||||||
|
1731
|
||||||
|
1886
|
||||||
|
1686
|
||||||
|
1150
|
||||||
|
1806
|
||||||
|
1960
|
||||||
|
1841
|
||||||
|
1936
|
||||||
|
1845
|
||||||
|
1520
|
||||||
|
1779
|
||||||
|
1102
|
||||||
|
1323
|
||||||
|
1892
|
||||||
|
1742
|
||||||
|
1941
|
||||||
|
1395
|
||||||
|
1525
|
||||||
|
1165
|
||||||
|
715
|
||||||
|
1829
|
||||||
|
1448
|
||||||
|
1906
|
||||||
|
1191
|
||||||
|
1981
|
||||||
|
1115
|
||||||
|
1716
|
||||||
|
1644
|
||||||
|
1310
|
||||||
|
1836
|
||||||
|
1105
|
||||||
|
1517
|
||||||
|
1790
|
||||||
|
1950
|
||||||
|
1741
|
||||||
|
1256
|
||||||
|
1467
|
||||||
|
1677
|
||||||
|
1372
|
||||||
|
1838
|
||||||
|
1637
|
||||||
|
1143
|
||||||
|
1763
|
||||||
|
1222
|
||||||
|
1291
|
||||||
|
1835
|
||||||
|
1602
|
||||||
|
1927
|
||||||
|
1933
|
||||||
|
1952
|
||||||
|
1692
|
||||||
|
1662
|
||||||
|
1967
|
||||||
|
1791
|
||||||
|
1984
|
||||||
|
1176
|
||||||
|
1324
|
||||||
|
1460
|
||||||
|
1416
|
||||||
|
562
|
||||||
|
1862
|
||||||
|
1273
|
||||||
|
1518
|
||||||
|
1535
|
||||||
|
1093
|
||||||
|
1977
|
||||||
|
1923
|
||||||
|
1246
|
||||||
|
1570
|
||||||
|
1674
|
||||||
|
1861
|
||||||
|
1811
|
||||||
|
1431
|
||||||
|
47
|
||||||
|
1158
|
||||||
|
1912
|
||||||
|
1322
|
||||||
|
1062
|
||||||
|
1407
|
||||||
|
1528
|
||||||
|
1068
|
||||||
|
1868
|
||||||
|
1997
|
||||||
|
1930
|
||||||
|
959
|
||||||
|
1676
|
||||||
|
1759
|
||||||
|
2000
|
||||||
|
1993
|
||||||
|
1722
|
||||||
|
1738
|
||||||
|
1264
|
||||||
|
1361
|
||||||
|
1542
|
||||||
|
1187
|
||||||
|
1735
|
||||||
|
1405
|
||||||
|
1745
|
||||||
|
1753
|
||||||
|
1833
|
||||||
|
1493
|
||||||
|
1311
|
||||||
|
1547
|
||||||
|
1180
|
||||||
|
1553
|
||||||
|
1513
|
||||||
|
1812
|
||||||
|
1951
|
||||||
|
1948
|
||||||
|
1834
|
||||||
|
1925
|
||||||
|
1726
|
||||||
|
1326
|
||||||
|
1931
|
||||||
|
1962
|
||||||
|
1947
|
||||||
|
1173
|
||||||
|
1633
|
||||||
|
1901
|
||||||
|
1781
|
||||||
|
1483
|
||||||
|
1789
|
||||||
|
1417
|
||||||
|
1929
|
||||||
|
1859
|
||||||
|
1760
|
||||||
|
1347
|
||||||
|
1996
|
||||||
|
1328
|
||||||
|
1798
|
||||||
|
1230
|
||||||
|
1298
|
||||||
|
1877
|
||||||
|
1840
|
||||||
|
1607
|
||||||
|
1253
|
||||||
|
1057
|
||||||
|
1650
|
||||||
|
1171
|
||||||
|
1593
|
||||||
6
day01/data/sample.txt
Normal file
6
day01/data/sample.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
1721
|
||||||
|
979
|
||||||
|
366
|
||||||
|
299
|
||||||
|
675
|
||||||
|
1456
|
||||||
140
day01/index.html
Normal file
140
day01/index.html
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<title>Day 1 - 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, ads, 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/adventofcode-2019" 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">2*</span></div></div><div><h1 class="title-event"> <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://www.hiddendreams.se/aoc" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">Hidden Dreams</a> - Vi gör på jobbet, vad du får göra på fritiden.</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 1: Report Repair ---</h2><p>After saving Christmas <a href="/events">five years in a row</a>, you've decided to take a vacation at a nice resort on a tropical island. <span title="WHAT COULD GO WRONG">Surely</span>, Christmas will go on without you.</p>
|
||||||
|
<p>The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them <em class="star">stars</em>. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room.</p>
|
||||||
|
<p>To save your vacation, you need to get all <em class="star">fifty stars</em> by December 25th.</p>
|
||||||
|
<p>Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants <em class="star">one star</em>. Good luck!</p>
|
||||||
|
<p>Before you leave, the Elves in accounting just need you to fix your <em>expense report</em> (your puzzle input); apparently, something isn't quite adding up.</p>
|
||||||
|
<p>Specifically, they need you to <em>find the two entries that sum to <code>2020</code></em> and then multiply those two numbers together.</p>
|
||||||
|
<p>For example, suppose your expense report contained the following:</p>
|
||||||
|
<pre><code>1721
|
||||||
|
979
|
||||||
|
366
|
||||||
|
299
|
||||||
|
675
|
||||||
|
1456
|
||||||
|
</code></pre>
|
||||||
|
<p>In this list, the two entries that sum to <code>2020</code> are <code>1721</code> and <code>299</code>. Multiplying them together produces <code>1721 * 299 = 514579</code>, so the correct answer is <code><em>514579</em></code>.</p>
|
||||||
|
<p>Of course, your expense report is much larger. <em>Find the two entries that sum to <code>2020</code>; what do you get if you multiply them together?</em></p>
|
||||||
|
</article>
|
||||||
|
<p>Your puzzle answer was <code>751776</code>.</p><article class="day-desc"><h2 id="part2">--- Part Two ---</h2><p>The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find <em>three</em> numbers in your expense report that meet the same criteria.</p>
|
||||||
|
<p>Using the above example again, the three entries that sum to <code>2020</code> are <code>979</code>, <code>366</code>, and <code>675</code>. Multiplying them together produces the answer, <code><em>241861950</em></code>.</p>
|
||||||
|
<p>In your expense report, <em>what is the product of the three entries that sum to <code>2020</code>?</em></p>
|
||||||
|
</article>
|
||||||
|
<p>Your puzzle answer was <code>42275090</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="1/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+%22Report+Repair%22+%2D+Day+1+%2D+Advent+of+Code+2020&url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F1&related=ericwastl&hashtags=AdventOfCode" target="_blank">Twitter</a>
|
||||||
|
<a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=I%27ve+completed+%22Report+Repair%22+%2D+Day+1+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F1'}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>
|
||||||
13
day01/run.py
Normal file
13
day01/run.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import itertools
|
||||||
|
with open('data/sample.txt') as f:
|
||||||
|
data = list(map(int,f.readlines()))
|
||||||
|
|
||||||
|
for x, y in itertools.combinations(data, 2):
|
||||||
|
if x+y == 2020:
|
||||||
|
print(x*y)
|
||||||
|
with open('data/data.txt') as f:
|
||||||
|
data = list(map(int,f.readlines()))
|
||||||
|
|
||||||
|
for x, y, z in itertools.combinations(data, 3):
|
||||||
|
if x+y+z == 2020:
|
||||||
|
print(x*y*z)
|
||||||
1000
day02/data/data.txt
Normal file
1000
day02/data/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
day02/data/sample.txt
Normal file
3
day02/data/sample.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
1-3 a: abcde
|
||||||
|
1-3 b: cdefg
|
||||||
|
2-9 c: ccccccccc
|
||||||
131
day02/index.html
Normal file
131
day02/index.html
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en-us">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<title>Day 2 - 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, ads, 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/adventofcode-2019" 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">2*</span></div></div><div><h1 class="title-event"> <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://www.twilio.com/quest?utm_source=advent-of-code-20&utm_medium=website" target="_blank" onclick="if(ga)ga('send','event','sponsor','sidebar',this.href);" rel="noopener">TwilioQuest</a> - Learn to code and lead your intrepid crew on a mission to save The Cloud in TwilioQuest, a PC role-playing game inspired by classics of the 16-bit era. Free forever, and available now for Windows, Mac, and Linux.</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 2: Password Philosophy ---</h2><p>Your flight departs in a few days from the coastal airport; the easiest way down to the coast from here is via <a href="https://en.wikipedia.org/wiki/Toboggan" target="_blank">toboggan</a>.</p>
|
||||||
|
<p>The shopkeeper at the North Pole Toboggan Rental Shop is having a bad day. "Something's wrong with our computers; we can't log in!" You ask if you can take a look.</p>
|
||||||
|
<p>Their password database seems to be a little corrupted: some of the passwords wouldn't have been allowed by the <span title="To ensure your safety, your password must be the following string...">Official Toboggan Corporate Policy</span> that was in effect when they were chosen.</p>
|
||||||
|
<p>To try to debug the problem, they have created a list (your puzzle input) of <em>passwords</em> (according to the corrupted database) and <em>the corporate policy when that password was set</em>.</p>
|
||||||
|
<p>For example, suppose you have the following list:</p>
|
||||||
|
<pre><code>1-3 a: abcde
|
||||||
|
1-3 b: cdefg
|
||||||
|
2-9 c: ccccccccc
|
||||||
|
</code></pre>
|
||||||
|
<p>Each line gives the password policy and then the password. The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, <code>1-3 a</code> means that the password must contain <code>a</code> at least <code>1</code> time and at most <code>3</code> times.</p>
|
||||||
|
<p>In the above example, <code><em>2</em></code> passwords are valid. The middle password, <code>cdefg</code>, is not; it contains no instances of <code>b</code>, but needs at least <code>1</code>. The first and third passwords are valid: they contain one <code>a</code> or nine <code>c</code>, both within the limits of their respective policies.</p>
|
||||||
|
<p><em>How many passwords are valid</em> according to their policies?</p>
|
||||||
|
</article>
|
||||||
|
<p>To begin, <a href="2/input" target="_blank">get your puzzle input</a>.</p>
|
||||||
|
<form method="post" action="2/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=%22Password+Philosophy%22+%2D+Day+2+%2D+Advent+of+Code+2020&url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F2&related=ericwastl&hashtags=AdventOfCode" target="_blank">Twitter</a>
|
||||||
|
<a href="javascript:void(0);" onclick="var mastodon_instance=prompt('Mastodon Instance / Server Name?'); if(typeof mastodon_instance==='string' && mastodon_instance.length){this.href='https://'+mastodon_instance+'/share?text=%22Password+Philosophy%22+%2D+Day+2+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F2'}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>
|
||||||
36
day02/module.py
Normal file
36
day02/module.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
from aoc.input import get_input
|
||||||
|
from aoc.partselector import part_one, part_two
|
||||||
|
|
||||||
|
def pw(line):
|
||||||
|
pol, pw = line.split(': ')
|
||||||
|
polcnt, l = pol.split(' ')
|
||||||
|
a, b = map(int,polcnt.split('-'))
|
||||||
|
return a, b, l, pw
|
||||||
|
|
||||||
|
inp = get_input(pw)
|
||||||
|
|
||||||
|
|
||||||
|
if part_one():
|
||||||
|
corrent = 0
|
||||||
|
for a, b, l, pw in inp:
|
||||||
|
count = 0
|
||||||
|
for i in pw:
|
||||||
|
if i == l:
|
||||||
|
count += 1
|
||||||
|
if count >= a and count <= b:
|
||||||
|
corrent += 1
|
||||||
|
print (corrent)
|
||||||
|
|
||||||
|
|
||||||
|
if part_two():
|
||||||
|
corrent = 0
|
||||||
|
for a, b, l, pw in inp:
|
||||||
|
count = 0
|
||||||
|
for z, i in enumerate(pw, start=1):
|
||||||
|
if z == a:
|
||||||
|
correct = i == l
|
||||||
|
if z == b:
|
||||||
|
correct = (bool(correct) != bool(i==l))
|
||||||
|
if correct:
|
||||||
|
corrent += 1
|
||||||
|
print (corrent)
|
||||||
Reference in New Issue
Block a user