day 06 && 07
This commit is contained in:
2242
day06/data/data.txt
Normal file
2242
day06/data/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
0
day06/data/sample.txt
Normal file
0
day06/data/sample.txt
Normal file
6
day06/index.html
Normal file
6
day06/index.html
Normal file
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<head><title>504 Gateway Time-out</title></head>
|
||||
<body>
|
||||
<center><h1>504 Gateway Time-out</h1></center>
|
||||
</body>
|
||||
</html>
|
||||
46
day06/module.py
Normal file
46
day06/module.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from aoc.input import get_input
|
||||
import collections
|
||||
import re
|
||||
from aoc.partselector import part_one, part_two
|
||||
|
||||
def pw(line):
|
||||
return line.strip()
|
||||
|
||||
def p1():
|
||||
inp = get_input(pw)
|
||||
groups = []
|
||||
group = []
|
||||
for i in inp:
|
||||
if i == '':
|
||||
groups.append(group)
|
||||
group = []
|
||||
else:
|
||||
group.append(i)
|
||||
|
||||
count = 0
|
||||
for g in groups:
|
||||
answers = set()
|
||||
for p in g:
|
||||
for x in p:
|
||||
answers.add(x)
|
||||
count += len(answers)
|
||||
print(count)
|
||||
return groups
|
||||
|
||||
|
||||
def p2(r):
|
||||
count = 0
|
||||
for g in r:
|
||||
s = set(g[0])
|
||||
for p in g[1:]:
|
||||
s = s.intersection(p)
|
||||
count += len(s)
|
||||
print(count)
|
||||
return 0
|
||||
|
||||
if part_one():
|
||||
result1 = p1()
|
||||
|
||||
|
||||
if part_two():
|
||||
p2(result1)
|
||||
594
day07/data/data.txt
Normal file
594
day07/data/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
9
day07/data/sample.txt
Normal file
9
day07/data/sample.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
light red bags contain 1 bright white bag, 2 muted yellow bags.
|
||||
dark orange bags contain 3 bright white bags, 4 muted yellow bags.
|
||||
bright white bags contain 1 shiny gold bag.
|
||||
muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
|
||||
shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
|
||||
dark olive bags contain 3 faded blue bags, 4 dotted black bags.
|
||||
vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
|
||||
faded blue bags contain no other bags.
|
||||
dotted black bags contain no other bags.
|
||||
7
day07/data/sample2.txt
Normal file
7
day07/data/sample2.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
shiny gold bags contain 2 dark red bags.
|
||||
dark red bags contain 2 dark orange bags.
|
||||
dark orange bags contain 2 dark yellow bags.
|
||||
dark yellow bags contain 2 dark green bags.
|
||||
dark green bags contain 2 dark blue bags.
|
||||
dark blue bags contain 2 dark violet bags.
|
||||
dark violet bags contain no other bags.
|
||||
143
day07/index.html
Normal file
143
day07/index.html
Normal file
@@ -0,0 +1,143 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Day 7 - 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">12*</span></div></div><div><h1 class="title-event"> <span class="title-event-wrap">$year=</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 7: Handy Haversacks ---</h2><p>You land at the regional airport in time for your next flight. In fact, it looks like you'll even have time to grab some food: all flights are currently delayed due to <em>issues in luggage processing</em>.</p>
|
||||
<p>Due to recent aviation regulations, many rules (your puzzle input) are being enforced about bags and their contents; bags must be color-coded and must contain specific quantities of other color-coded bags. Apparently, nobody responsible for these regulations considered how long they would take to enforce!</p>
|
||||
<p>For example, consider the following rules:</p>
|
||||
<pre><code>light red bags contain 1 bright white bag, 2 muted yellow bags.
|
||||
dark orange bags contain 3 bright white bags, 4 muted yellow bags.
|
||||
bright white bags contain 1 shiny gold bag.
|
||||
muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
|
||||
shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
|
||||
dark olive bags contain 3 faded blue bags, 4 dotted black bags.
|
||||
vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
|
||||
faded blue bags contain no other bags.
|
||||
dotted black bags contain no other bags.
|
||||
</code></pre>
|
||||
<p>These rules specify the required contents for 9 bag types. In this example, every <code>faded blue</code> bag is empty, every <code>vibrant plum</code> bag contains 11 bags (5 <code>faded blue</code> and 6 <code>dotted black</code>), and so on.</p>
|
||||
<p>You have a <code><em>shiny gold</em></code> bag. If you wanted to carry it in at least one other bag, how many different bag colors would be valid for the outermost bag? (In other words: how many colors can, eventually, contain at least one <code>shiny gold</code> bag?)</p>
|
||||
<p>In the above rules, the following options would be available to you:</p>
|
||||
<ul>
|
||||
<li>A <code>bright white</code> bag, which can hold your <code>shiny gold</code> bag directly.</li>
|
||||
<li>A <code>muted yellow</code> bag, which can hold your <code>shiny gold</code> bag directly, plus some other bags.</li>
|
||||
<li>A <code>dark orange</code> bag, which can hold <code>bright white</code> and <code>muted yellow</code> bags, either of which could then hold your <code>shiny gold</code> bag.</li>
|
||||
<li>A <code>light red</code> bag, which can hold <code>bright white</code> and <code>muted yellow</code> bags, either of which could then hold your <code>shiny gold</code> bag.</li>
|
||||
</ul>
|
||||
<p>So, in this example, the number of bag colors that can eventually contain at least one <code>shiny gold</code> bag is <code><em>4</em></code>.</p>
|
||||
<p><em>How many bag colors can eventually contain at least one <code>shiny gold</code> bag?</em> (The list of rules is quite long; make sure you get all of it.)</p>
|
||||
</article>
|
||||
<p>To begin, <a href="7/input" target="_blank">get your puzzle input</a>.</p>
|
||||
<form method="post" action="7/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=%22Handy+Haversacks%22+%2D+Day+7+%2D+Advent+of+Code+2020&url=https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F7&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=%22Handy+Haversacks%22+%2D+Day+7+%2D+Advent+of+Code+2020+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2020%2Fday%2F7'}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>
|
||||
85
day07/module.py
Normal file
85
day07/module.py
Normal file
@@ -0,0 +1,85 @@
|
||||
from aoc.input import get_input
|
||||
import time
|
||||
import collections
|
||||
import re
|
||||
from aoc.partselector import part_one, part_two
|
||||
|
||||
def pw(line):
|
||||
return line.strip().split(' ')
|
||||
|
||||
def p1():
|
||||
inp = get_input(pw)
|
||||
pwd = dict()
|
||||
for i in inp:
|
||||
key = ''.join(i[0:2])
|
||||
data = []
|
||||
for n in range (4, len(i), 4):
|
||||
if i[n] == 'no':
|
||||
continue
|
||||
data.append(''.join(i[n+1:n+3]).strip('., '))
|
||||
pwd[''.join(key)] = data
|
||||
|
||||
count = 0
|
||||
|
||||
def contains_gold(y):
|
||||
if 'shinygold' == y:
|
||||
return True
|
||||
else:
|
||||
ret = False
|
||||
for j in pwd[y]:
|
||||
ret = ret | contains_gold(j)
|
||||
return ret
|
||||
|
||||
for j in pwd:
|
||||
ret = False
|
||||
for t in pwd[j]:
|
||||
ret |= contains_gold(t)
|
||||
if ret:
|
||||
count += 1
|
||||
|
||||
|
||||
print(count)
|
||||
return count
|
||||
|
||||
|
||||
def p2(r):
|
||||
inp = get_input(pw)
|
||||
pwd = dict()
|
||||
for i in inp:
|
||||
key = ''.join(i[0:2])
|
||||
data = []
|
||||
for n in range (4, len(i), 4):
|
||||
if i[n] == 'no':
|
||||
continue
|
||||
data.append([int(i[n]), ''.join(i[n+1:n+3]).strip('., ')])
|
||||
pwd[''.join(key)] = data
|
||||
|
||||
count = 0
|
||||
|
||||
def count_bags(y):
|
||||
count = 1
|
||||
for j in pwd[y]:
|
||||
tmpcount = count_bags(j[1])
|
||||
count += tmpcount * j[0]
|
||||
return count
|
||||
|
||||
ret = 0
|
||||
for t in pwd['shinygold']:
|
||||
ret += count_bags(t[1]) * t[0]
|
||||
|
||||
|
||||
print(ret)
|
||||
return 0
|
||||
|
||||
if part_one():
|
||||
start = time.time()
|
||||
result1 = p1()
|
||||
print(round(time.time() - start, 4), 's')
|
||||
|
||||
|
||||
if part_two():
|
||||
start = time.time()
|
||||
p2(0)
|
||||
print(round(time.time() - start, 4), 's')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user