move to 2020 fodler

This commit is contained in:
2021-12-01 11:43:46 +01:00
parent 1139eb9cd6
commit e88c99bb86
60 changed files with 0 additions and 0 deletions

129
2020/.gitignore vendored Normal file
View File

@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/

9
2020/README.md Normal file
View File

@@ -0,0 +1,9 @@
# Advent Of Code Solutions
Here are my solutions for the advent of code 2020 🎄🎅
Note that the exact solutions are different for some people.
The main ones are solved in python. 1-4 I also did in Go, but I quickly [did not like it](./learning/Go.md).
`/solutions/:day/*`

15
2020/learning/Go.md Normal file
View File

@@ -0,0 +1,15 @@
# Go Learning
So this will be my first time at writing some go.
Please excuse me for the ranting 😅
## WTFs
- Why is there no bitwise OR for bools?! Please what? XOR == `a != b`, but still...
- `math.Max()` only works with floats. Of course.
- so apparently we don't have optional parameters and defaults. Lol
- go has maps, but no native way of getting keys or values without a loop
## Syntax
- we constantly need to write `:=` which is annoying as hell

View File

@@ -0,0 +1,12 @@
# 1
This is quite simple, just iterate and find.
<details>
<summary>Solutions</summary>
<ol>
<li>1224 and 796 -> 974304</li>
<li>332, 858 and 830 -> 236430480</li>
</ol>
</details>

200
2020/solutions/1/data.txt Normal file
View File

@@ -0,0 +1,200 @@
1472
1757
1404
1663
1365
1974
1649
1489
1795
1821
1858
1941
1943
1634
1485
1838
817
1815
1442
639
1182
1632
1587
1918
1040
1441
1784
1725
1951
1285
285
1224
1755
1748
1488
1374
1946
1771
1809
1929
1621
1462
2001
1588
1888
1959
1787
1690
1363
1567
1853
1990
1819
1904
1458
1882
1348
1957
1454
1557
1471
332
1805
1826
1745
1154
1423
1852
1751
1194
1430
1849
1962
1577
1470
1509
1673
1883
1479
1487
2007
1555
1504
1570
2004
978
1681
1631
1791
1267
1245
1383
1482
1355
1792
1806
1376
1199
1391
1759
1474
1268
1942
1936
1766
1233
1876
1674
1761
1542
1468
1543
1986
2005
1689
1606
1865
1783
1807
1779
1860
1408
1505
1435
1205
1952
1201
1714
1743
1872
1897
1978
1683
1846
858
1528
1629
1510
1446
1869
1347
685
1478
1387
687
1964
1968
1429
1460
1777
1417
1768
1672
1767
1400
1914
1715
1425
1700
1756
1835
1926
1889
1568
1393
1960
1540
1810
1401
1685
830
1789
1652
1899
796
1483
1261
1398
1727
1566
1812
1937
1993
1286
1992
1611
1825
1868
1870
1746
1361
1418
1820
1598
1911
1428
1734
1833
1436
1560

View File

@@ -0,0 +1,55 @@
package main
import (
"fmt"
"io/ioutil"
"strconv"
"strings"
)
const target uint64 = 2020
func findTwo(list []uint64) {
for _, a := range list {
for _, b := range list {
if a+b == target {
fmt.Printf("The numbers: %v and %v.\tSolution: %v\n", a, b, a*b)
return
}
}
}
}
func findThree(list []uint64) {
for _, a := range list {
for _, b := range list {
for _, c := range list {
if a+b+c == target {
fmt.Printf("The numbers: %v, %v and %v.\tSolution: %v\n", a, b, c, a*b*c)
return
}
}
}
}
}
func main() {
data, err := ioutil.ReadFile("./solutions/1/data.txt")
if err != nil {
fmt.Println("File reading error", err)
return
}
lines := strings.Split(strings.TrimSpace(string(data)), "\n")
intLines := []uint64{}
for _, i := range lines {
num, _ := strconv.ParseUint(i, 10, 64)
intLines = append(intLines, num)
}
// fmt.Println("Result: ", findTwo(intLines))
// fmt.Println("Result: ", findThree(intLines))
findTwo(intLines)
findThree(intLines)
}

View File

@@ -0,0 +1,17 @@
from typing import List
from itertools import product
from os.path import join, dirname
target = 2020
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
numbers: List[int] = list(map(int, f.readlines()))
for a, b in product(numbers, numbers):
if a + b == target:
print(f'The numbers: {a} and {b}.\tSolution: {a*b}')
break
for a, b, c in product(numbers, numbers, numbers):
if a + b + c == target:
print(f'The numbers: {a}, {b} and {c}.\tSolution: {a*b*c}')
break

View File

@@ -0,0 +1,6 @@
1721
979
366
299
675
1456

View File

@@ -0,0 +1,43 @@
# 10
# First
The first one is really easy. Just sort, make the diff and count.
First I take the list and sort it:
```python
[16, 10, 15, 5, 1, 11, 7, 19, 6, 12, 4]
[0, 1, 4, 5, 6, 7, 10, 11, 12, 15, 16, 19, 22] # Sorted and added the wall plug (0) and the phone (biggest + 3)
[1, 3, 1, 1, 1, 3, 1, 1, 3, 1, 3, 3] # The size of each step
```
Now we can simply count how many `1` and `3` there are with `l.count(1)`.
## Second
This is where it gets tricky.
First lets find all the consecutive `1`s ad only they can be removed. If we have more than 1 consecutive `1` we can remove one of it. However we need to be careful not to remove to many or the step will be higher than `3` and the chain breaks.
```python
[1, 1, 1, 1] # We can transform this example by adding 2 numbers together and "joining" them.
[1, 2, 1] # Valid
[1, 1, 2] # Valid
[1, 3] # Valid
[4] # Invalid because we can jump a max of 3 steps at a time.
```
Now we could iterate but I wanted to find a formula. Not sure this is correct but here we go.
Basically we take the length of the consecutive `1` and compute `2**(l-1)` to get all possible combinations.
Now we need to subtract the possible `4` which can only be achieved if we have at least 4 numbers -> `floor(l/4)`
For a grand total of `2**(l-1) - floor(l/4)`
<details>
<summary>Solutions</summary>
<ol>
<li>2475</li>
<li>442136281481216</li>
</ol>
</details>

107
2020/solutions/10/data.txt Normal file
View File

@@ -0,0 +1,107 @@
48
171
156
51
26
6
80
62
65
82
130
97
49
31
142
83
75
20
154
119
56
114
92
33
140
74
118
1
96
44
128
134
121
64
158
27
17
101
59
12
89
88
145
167
11
3
39
43
105
16
170
63
111
2
108
21
146
77
45
52
32
127
147
76
58
37
86
129
57
133
120
163
138
161
139
71
9
141
168
164
124
157
95
25
38
69
87
155
135
15
102
70
34
42
24
50
68
169
10
55
117
30
81
151
100
162
148

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

View File

@@ -0,0 +1,54 @@
from os.path import join, dirname
from typing import List, Optional, Set, Tuple
from itertools import combinations, count
from math import floor, prod
def parse(s: str) -> List[int]:
numbers: List[int] = sorted(map(int, s.strip().split('\n')))
numbers.insert(0, 0) # The wall
numbers.append(numbers[-1] + 3) # Phone itself
return numbers
def diff(l: List[int]) -> List[int]:
return [
l[x] - l[x-1]
for x in range(1, len(l))
]
def calc(d: List[int]) -> int:
one = d.count(1)
three = d.count(3)
return one * three
def find_valid_permutations(d: List[int]) -> int:
i = 0
l = len(d)
slices: List[int] = []
while i < l:
if d[i] != 3:
try:
n = d.index(3, i + 1) # Find the next three
diff = n - i
if diff > 1:
slices.append(diff)
i = n
continue
except:
pass
i += 1
return prod([
2**(s-1) - floor(s/4)
for s in slices
])
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
numbers: List[int] = parse(f.read())
d = diff(numbers)
print(calc(d))
print(find_valid_permutations(d))

View File

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

View File

@@ -0,0 +1,12 @@
# 11
Today: Game of life, but a bit different :)
I lost so much time because I missed that in the second part we now require 5 instead of 4 occupied seats 😩
<details>
<summary>Solutions</summary>
<ol>
<li>2296</li>
<li>2089</li>
</ol>
</details>

View File

@@ -0,0 +1,91 @@
LLLLLLLLLLL.LLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLLLL.LLL.LLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLLLLLLL
LLLLLL.LLLLLLLLLL.LLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL
LLLLLLLLLLL.LLLLL.LLLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLL.LLLLLL.LLLLLL.LLLLLLLLLLLLL
LLLLLL.LLLLLLLLLL.LLLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLL.L.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LLLLLL.LLLL.LLLLL.LLLL.LLLLLLL.LLLLLLL.LLLLL.LLLLLLLLL.LLLLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLLLLLLLL
LLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLL
LLLLLL.LLLL.LLLLL.LLLLLLLLLLLLLLLLLLLL..LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLL
.L..LLL...L....LLLL.L..L...............LLLLLL..LL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L..LL...L....L.....
LLLLLL.LLLLLLLLLL..LLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLLLL.LLLLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLLLLLLLL
LLLLLLLLLLLLLLLLL.LLLLLL.LLLLL.LLLL.LL.LLLLLL.LLLLLLLL.LLLLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLLLLLLLL
LLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLLLLLLL
LLLL.LL.LLLLLLL.L.LLLLLL.LLLLL.LLLLLLLLLLLLL.LLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLL.LLLLL.LLLLLLLLLLLLL
LLLLLLLLLLL.LLLLL.LLLLLL.LLLLLLLLLLLLL..LLLLLLLLLLLLLLLLLLLLLLL.LL.LLLLLLLLLL.LLLLL.LLLLLLLLLLLLL
LLLLLLLLLLL.LLLLLLLLLLLLLLL.LL.LLLLLLLL..LLL.LLLLLLLLL.LLLLLLLLLLL.LLLLLLLLLL.LLLLL.LLLLLLLLLLLLL

View File

@@ -0,0 +1,99 @@
from os.path import join, dirname
from typing import List, Optional
from itertools import product
from copy import deepcopy
TSeats = List[List[Optional[bool]]]
mapping = {
'.': None,
'#': True,
'L': False
}
inv = {v: k for k, v in mapping.items()}
class Seats:
p = [-1, 0, 1]
def __init__(self, plan: str, alt: bool = False) -> None:
self.seats: TSeats = [
[
mapping[seat]
for seat in row
]
for row in plan.strip().split('\n')
]
self.max_x = len(self.seats[0])
self.max_y = len(self.seats)
self.alt = alt
def __str__(self) -> str:
return '\n'.join([
''.join([inv[seat] for seat in row])
for row in self.seats
])
def find_next_in_direction(self, y: int, x: int, dy: int, dx: int) -> Optional[bool]:
y += dy
x += dx
while 0 <= x < self.max_x and 0 <= y < self.max_y:
cur = self.seats[y][x]
if cur is not None:
return cur
y += dy
x += dx
return None
def get_occupied(self, y: int, x: int,) -> int:
occupied = 0
for dx, dy in product(self.p, self.p):
if dx == 0 and dy == 0:
continue
if self.alt and self.find_next_in_direction(y, x, dy, dx) == True:
occupied += 1
else:
dx += x
dy += y
if 0 <= dx < self.max_x and 0 <= dy < self.max_y and self.seats[dy][dx]:
occupied += 1
return occupied
def iteration(self) -> int:
changed = 0
future: TSeats = deepcopy(self.seats)
required_to_leave = 4 if self.alt else 3
for y, x in product(range(self.max_y), range(self.max_x)):
current = self.seats[y][x]
if current == None:
continue
occupied = self.get_occupied(y, x)
if (current == True and occupied > required_to_leave) or (current == False and occupied == 0):
future[y][x] = not current
changed += 1
self.seats = future
return changed
def count_occupied(self) -> int:
return sum([
sum([
1 if seat == True else 0
for seat in row
])
for row in self.seats
])
def find_equilibrium(self) -> int:
while self.iteration() > 0:
pass
return self.count_occupied()
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
txt = f.read()
seats = Seats(txt)
print(seats.find_equilibrium())
seats = Seats(txt, True)
print(seats.find_equilibrium())

View File

@@ -0,0 +1,10 @@
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

View File

@@ -0,0 +1,13 @@
# 12
Let's navigate!
Reminded me that I had to refresh trigonometry a bit xD
<details>
<summary>Solutions</summary>
<ol>
<li>796</li>
<li>39446</li>
</ol>
</details>

773
2020/solutions/12/data.txt Normal file
View File

@@ -0,0 +1,773 @@
R180
S1
F44
R90
E5
N3
E5
S4
W1
F68
E2
L90
F40
W3
N2
L180
S3
R90
R90
W5
F45
L90
F9
W5
N1
E1
F39
R90
F6
E3
N1
E2
N3
L180
N5
L90
L90
S2
F72
L90
E5
L90
S2
F79
N3
R90
F25
R90
F16
W2
L90
F81
W5
L90
E5
S3
W5
N1
L180
F73
N1
F60
S3
E1
F65
W1
R90
F36
S4
W1
R90
S2
F33
S5
L90
E3
F11
S4
W2
L90
F57
W4
N1
R180
S2
F87
N2
E2
S2
F89
L90
W1
N3
F63
R270
W4
N1
R90
F67
L90
F74
N5
W5
S3
L90
N1
L180
W4
S4
E1
L90
S1
E4
S3
F95
S4
F32
L90
F9
R180
N4
W3
R90
W4
F10
W5
F21
L180
F17
S4
L90
F24
R90
F1
E5
R180
F63
N5
N4
E1
F73
S2
S5
W1
N1
R90
F77
W4
N4
F74
W5
F82
W4
F8
E4
N2
R90
R90
E3
F44
F42
L90
W5
R90
W5
F45
W5
F35
W1
L90
S1
L90
N5
R90
F4
R180
F19
R180
F16
W5
S1
R90
S2
W3
F44
S4
W4
F95
R180
F1
R90
F36
N4
F12
R90
F26
F14
R90
E5
N1
W2
F88
N5
R180
S2
E4
R90
N4
E4
S2
F9
N2
E3
N5
F28
N4
E3
N3
W3
F93
N2
R180
E2
F9
W1
F28
R90
S1
F82
W4
S1
F59
S2
F7
E2
R180
E5
F19
S3
E4
F53
L270
E1
L90
W3
F2
S3
F40
E3
S1
F94
W3
L90
F87
W3
F37
S5
E2
N2
R270
F55
R90
S1
W2
N1
L90
F21
W5
N4
L90
N3
F50
F18
N2
F3
W5
F68
N5
L90
R270
F31
L90
F90
R90
E3
N3
L90
F97
S1
W2
N2
F10
E1
W3
S4
F56
R270
F70
S1
L90
E1
F89
W2
F94
L180
F94
R90
N4
F89
R180
W5
F81
R90
N3
F61
W3
W5
W2
F90
F66
N5
R90
E2
F31
L90
E4
E1
R180
W5
F8
W3
R90
F92
R90
E1
R90
E2
F66
E5
R90
S2
R90
W5
R90
F52
S5
E2
N1
F57
W1
F30
W5
F51
N3
F82
L90
S1
W4
R90
W5
N5
E5
N5
F41
N3
R90
S3
E1
R90
W2
N5
W5
F45
L270
F93
E4
R270
F95
S3
W2
N3
R90
W2
E2
F56
R90
N4
E3
R90
W3
N4
F54
R90
E5
F86
E3
R90
F8
N1
F79
S3
E1
N2
F90
L90
E2
R90
W2
F95
E2
L90
E1
F47
W3
L90
F78
L90
W3
R90
N1
F34
W2
L90
W4
R90
W2
R180
E3
S5
W2
F61
W3
R90
E5
F30
S3
F11
W4
S2
F33
R270
F94
L270
S3
L90
F48
R180
S4
F17
N4
F64
L90
N5
R90
S3
N4
F53
S5
W5
L180
E3
F96
R90
F48
R180
F84
E4
R270
F48
F32
R90
F79
S2
R90
E5
S4
L90
S5
F5
W4
F30
R180
S2
E3
N4
F80
E1
F75
E5
L90
S2
W3
F87
L90
F57
S5
F78
N5
E2
E2
F53
N5
F58
E4
R90
N3
E1
S4
W2
N3
R180
W4
S1
F17
R90
N4
W4
S3
W1
R90
S4
R90
N1
W4
N2
F17
R90
N1
L90
S3
E4
S3
R90
F66
E2
N4
W4
S1
L90
F56
R180
S5
F43
E5
F44
E5
S2
E2
R180
F64
N4
W5
L180
E2
L90
N4
E5
F75
L90
E3
L90
F79
R180
E2
L90
F88
S4
W3
R90
E3
F43
E3
F43
N1
W4
S3
F55
N4
F52
E3
L180
E2
N2
F80
R180
S5
F92
N3
W2
R90
E2
L90
W3
S4
L90
N5
E1
L180
F25
W4
F65
E1
S5
R90
N4
F4
E4
F70
F26
N2
N4
W2
F3
R90
N5
F84
W1
R90
N4
W4
F43
R270
S2
F2
S4
L90
F59
L90
F59
R90
S5
F88
L90
N5
E2
F7
S2
W5
L90
S4
R270
F5
L90
E1
F25
E1
S5
F84
L180
F10
W3
L180
S4
F51
N1
W2
L90
F23
W4
N1
E2
F40
W5
N3
F93
R180
E5
S1
E5
F11
S1
E2
L90
E2
F11
R270
W4
L180
N3
R90
F5
L90
R90
N2
F50
R180
S1
E2
S4
E3
N4
W2
F69
E1
N1
W4
R90
F68
W3
S2
F5
W2
S2
S4
R180
W1
R90
F14
E5
S3
W2
F84
E1
L90
F99
S4
S4
W1
F31
E4
F77
S4
F75
R90
W3
R90
L90
E5
N4
W3
L90
E2
L90
W1
F91
L90
E2
L90
N1
E1
R180
S1
L90
F72
W2
R270
F18
N5
F7
E3
F83
W5
E1
S3
E3
F76
S5
L90
S4
E2
S1
R270
F52
R270
F51
N2
F41
N1
E5
S3
R90
W4
F53

View File

@@ -0,0 +1,83 @@
from os.path import join, dirname
from typing import List, Optional
from math import cos, sin, radians, atan2, degrees, sqrt
directions = {
'N': 0,
'E': 90,
'S': 180,
'W': 270,
}
class Ship:
def __init__(self, waypoint=False) -> None:
self.x: float = 0
self.y: float = 0
self.d: int = directions['E']
self.waypoint = waypoint
self.wx: float = 10
self.wy: float = 1
@property
def distance(self) -> int:
return round(abs(self.x) + abs(self.y))
def __str__(self) -> str:
return f'⛴ X={round(self.x)} Y={round(self.y)} 𒎓={round(self.d)}\t🏴‍☠️ X={round(self.wx)} Y={round(self.wy)}'
def navigate(self, amount: int, degree: Optional[int] = None) -> None:
if degree == None:
if self.waypoint:
self.x += self.wx * amount
self.y += self.wy * amount
return
degree = self.d
dx = amount * sin(radians(degree))
dy = amount * cos(radians(degree))
if self.waypoint:
self.wx += dx
self.wy += dy
else:
self.x += dx
self.y += dy
def move(self, instruction: str) -> None:
cmd: str = instruction[0]
amount: int = int(instruction[1:])
if cmd in directions:
self.navigate(amount, degree=directions[cmd])
elif cmd == 'F':
self.navigate(amount)
else:
diff = amount if cmd == 'R' else -amount
if self.waypoint:
size = sqrt(self.wx**2 + self.wy**2)
d = degrees(atan2(self.wy, self.wx))
d -= diff
self.wx = size * cos(radians(d))
self.wy = size * sin(radians(d))
else:
self.d = (self.d + diff) % 360
def follow(self, file: str) -> None:
instructions = file.strip().split('\n')
for instruction in instructions:
self.move(instruction)
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
txt = f.read()
ship = Ship()
ship.follow(txt)
print(ship)
print(ship.distance)
ship = Ship(waypoint=True)
ship.follow(txt)
print(ship)
print(ship.distance)

View File

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

View File

@@ -0,0 +1,12 @@
# 13
The second part one was really interesting. While my solution is correct, it takes way to much time in the data set.
I started by checking what is the biggest ID number and check each location.
<details>
<summary>Solutions</summary>
<ol>
<li>156</li>
<li>404517869995362</li>
</ol>
</details>

View File

@@ -0,0 +1,2 @@
1000299
41,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,x,x,x,x,x,x,x,x,37,x,x,x,x,x,971,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,17,13,x,x,x,x,23,x,x,x,x,x,29,x,487,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,19

View File

@@ -0,0 +1,76 @@
from os.path import join, dirname
from typing import List, Tuple
from math import ceil, floor
class Station:
def __init__(self, txt: str) -> None:
arrival, busses = txt.strip().split('\n')
self.arrival = int(arrival)
self.busses = [
int(bus)
for bus in busses.replace('x', '0').split(',')
]
@staticmethod
def get_next_for_id(id: int, arrival: int) -> int:
return id * ceil(arrival / id)
def find_next(self) -> Tuple[int, int]:
arrivals: List[Tuple[int, int]] = []
for bus in self.busses:
if bus == 0:
continue
arrivals.append((bus, self.get_next_for_id(bus, self.arrival)))
return min(arrivals, key=lambda x: x[1])
def get_flag(self) -> int:
id, arrives = self.find_next()
return id * (arrives - self.arrival)
def contest(self, offset: int = 1) -> int:
# Prepare
highest = max(self.busses)
highest_i = self.busses.index(highest)
others = [
(bus, i - highest_i)
for i, bus in enumerate(self.busses)
if bus != 0 and i != highest_i
]
others.sort(key=lambda x: x[0], reverse=True)
# Compute
i: int = max(1, floor(offset / highest))
while True:
x = highest * i
error = False
for bus, diff in others:
dx = x + diff
if dx != self.get_next_for_id(bus, dx):
error = True
break
if not error:
return x - highest_i
i += 1
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
# Some "testing"
all = {
'17,x,13,19': 3417,
'67,7,59,61': 754018,
'67,x,7,59,61': 779210,
'67,7,x,59,61': 1261476,
'1789,37,47,1889': 1202161486,
}
for busses, expected in all.items():
station = Station('69\n' + busses)
print(expected, expected == station.contest())
txt = f.read()
station = Station(txt)
print(station.get_flag())
print(station.contest(offset=10**14))

View File

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

View File

@@ -0,0 +1,2 @@
69
67,7,x,59,61

View File

@@ -0,0 +1,14 @@
# 2
For the first we can simply count the occurrences and see if they are between the accepted values.
Just some simple parsing.
The second one is similar, but we can be more efficient if we XOR the first and second position.
<details>
<summary>Solutions</summary>
<ol>
<li>548</li>
<li>502</li>
</ol>
</details>

1000
2020/solutions/2/data.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
package main
import (
"fmt"
"io/ioutil"
"strconv"
"strings"
)
type sRow struct {
min, max int
char, password string
}
func parse(data []byte) []sRow {
parsed := []sRow{}
for _, row := range strings.Split(strings.TrimSpace(string(data)), "\n") {
s0 := strings.Split(row, ":")
rule := strings.TrimSpace(s0[0])
password := strings.TrimSpace(s0[1])
s1 := strings.Split(rule, " ")
minMax := strings.TrimSpace(s1[0])
char := strings.TrimSpace(s1[1])
s2 := strings.Split(minMax, "-")
min, _ := strconv.Atoi(strings.TrimSpace(s2[0]))
max, _ := strconv.Atoi(strings.TrimSpace(s2[1]))
r := sRow{
min: min,
max: max,
char: char,
password: password,
}
parsed = append(parsed, r)
}
return parsed
}
func validSimple(rows []sRow) int {
valid := 0
for _, row := range rows {
count := strings.Count(row.password, row.char)
if row.min <= count && count <= row.max {
valid++
}
}
return valid
}
func validComplex(rows []sRow) int {
valid := 0
for _, row := range rows {
l := len(row.password)
min := row.min - 1
max := row.max - 1
if min >= l || max >= l {
continue
}
r := []rune(row.password)
a := string(r[min]) == row.char
b := string(r[max]) == row.char
if a != b {
valid++
}
}
return valid
}
func main() {
data, _ := ioutil.ReadFile("./solutions/2/data.txt")
rows := parse(data)
simple := validSimple(rows)
fmt.Println(simple)
complex := validComplex(rows)
fmt.Println(complex)
}

View File

@@ -0,0 +1,27 @@
from os.path import join, dirname
def checkRow(row: str, alternative=False) -> bool:
rule, password = map(lambda s: s.strip(), row.split(':'))
amount, char = rule.split(' ')
minimum, maximum = map(int, amount.split('-'))
if alternative:
return (password[minimum - 1] == char) ^ (password[maximum - 1] == char)
else:
occurrences = password.count(char)
return minimum <= occurrences <= maximum
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
valid = 0
valid_alt = 0
rows = list(f.read().strip().split('\n'))
for row in rows:
if(checkRow(row)):
valid += 1
if(checkRow(row, alternative=True)):
valid_alt += 1
print(f'Found {valid} valid passwords.')
print('Policy changed...')
print(f'Found {valid_alt} valid passwords.')

View File

@@ -0,0 +1,16 @@
# 3
We can simply parse the forest as an array of strings.
The trees repeat infinitely to the right, this screams for a good mod.
This means: `char = row[x % len(row)]`. No complex logic needed
For the second one we simply automate the process and sum up the total.
We can simply encode the coordinates as a function of the index we are current at.
<details>
<summary>Solutions</summary>
<ol>
<li>252</li>
<li>57 * 252 * 64 * 66 * 43 = 2608962048</li>
</ol>
</details>

323
2020/solutions/3/data.txt Normal file
View File

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

View File

@@ -0,0 +1,66 @@
package main
import (
"fmt"
"io/ioutil"
"strings"
)
const high = rune('#')
type sForest struct {
data [][]bool
height int
width int
}
func (f sForest) at(y, x int) bool {
if y >= f.height {
return false
}
return f.data[y][x%f.width]
}
func (f sForest) traverse(y, x int) int {
trees := 0
for dy := 0; dy <= f.height; dy++ {
tree := f.at(dy*y, dy*x)
if tree {
trees++
}
}
return trees
}
func main() {
data, _ := ioutil.ReadFile("./solutions/3/data.txt")
rows := strings.Split(strings.TrimSpace(string(data)), "\n")
height, width := len(rows), len(rows[0])
d := make([][]bool, height)
for y, row := range rows {
d[y] = make([]bool, width)
for x, char := range []rune(row) {
d[y][x] = char == high
}
}
forest := sForest{
data: d,
height: height,
width: width,
}
fmt.Println("Simple: ", forest.traverse(1, 3))
trees11 := forest.traverse(1, 1)
trees13 := forest.traverse(1, 3)
trees15 := forest.traverse(1, 5)
trees17 := forest.traverse(1, 7)
trees21 := forest.traverse(2, 1)
fmt.Println(trees11, trees13, trees15, trees17, trees21)
fmt.Println(trees11 * trees13 * trees15 * trees17 * trees21)
}

View File

@@ -0,0 +1,50 @@
from typing import Dict
from os.path import join, dirname
from functools import reduce
class Forest():
def __init__(self, text: str) -> None:
self.text = text.strip().split('\n')
@property
def height(self) -> int:
return len(self.text)
def is_tree_at(self, y: int, x: int) -> bool:
if y > self.height:
return False
row = self.text[y]
return row[x % len(row)] == '#'
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
forest = Forest(f.read())
# 1
trees: int = 0
for y in range(forest.height):
is_tree: bool = forest.is_tree_at(y, y*3)
if is_tree:
trees += 1
print(f'Result Simple: {trees}')
# 2
all: Dict[str, int] = {
'11': 0,
'13': 0,
'15': 0,
'17': 0,
'21': 0,
}
for i in range(forest.height):
for key, value in all.items():
dy, dx = map(int, list(key))
y = i * dy
x = i * dx
if forest.is_tree_at(y, x):
all[key] += 1
total = reduce((lambda x, y: x * y), all.values())
print(f'Result Combined: {list(all.values())} = {total}')

11
2020/solutions/3/test.txt Normal file
View File

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

View File

@@ -0,0 +1,14 @@
# 4
This one was a lot of parsing, but nothing regexp can't do.
The first is quite straight forward, just check that all but `cid` are present.
The second was a bit of validation for each field, but again some simple regexp and number checking and the job is done 🙂
<details>
<summary>Solutions</summary>
<ol>
<li>206</li>
<li>123</li>
</ol>
</details>

1023
2020/solutions/4/data.txt Normal file

File diff suppressed because it is too large Load Diff

103
2020/solutions/4/go/main.go Normal file
View File

@@ -0,0 +1,103 @@
package main
import (
"fmt"
"io/ioutil"
"regexp"
"strconv"
"strings"
k "github.com/wesovilabs/koazee"
)
type tPassport = map[string]string
func stringBetween(s string, min, max int) bool {
num, _ := strconv.Atoi(s)
return min <= num && num <= max
}
func verifyPassport(passport tPassport) (bool, bool) {
requiredKeys := k.StreamOf([]string{"byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"})
eyeColors := k.StreamOf([]string{"amb", "blu", "brn", "gry", "grn", "hzl", "oth"})
// Simple
counted := 0
for k := range passport {
if k == "cid" {
continue
}
included, _ := requiredKeys.Contains(k)
if !included {
return false, false
}
counted++
}
if counted < 7 {
return false, false
}
// Complex
if !stringBetween(passport["byr"], 1920, 2002) || !stringBetween(passport["iyr"], 2010, 2020) || !stringBetween(passport["eyr"], 2020, 2030) {
return true, false
}
tmp := []rune(passport["hgt"])
hgtLen := len(tmp)
hgt, _ := strconv.Atoi(string(tmp[0 : hgtLen-2]))
unit := string(tmp[hgtLen-2:])
if unit != "cm" && unit != "in" {
return true, false
}
if unit == "cm" && (hgt < 150 || hgt > 193) {
return true, false
}
if unit == "in" && (hgt < 59 || hgt > 76) {
return true, false
}
if !regexp.MustCompile(`^#[\dabdcdef]{6}$`).MatchString(passport["hcl"]) {
return true, false
}
if !regexp.MustCompile(`^\d{9}$`).MatchString(passport["pid"]) {
return true, false
}
ecl, _ := eyeColors.Contains(passport["ecl"])
if !ecl {
return true, false
}
return true, true
}
func main() {
data, _ := ioutil.ReadFile("./solutions/4/data.txt")
passportsRaw := strings.Split(strings.TrimSpace(string(data)), "\n\n")
passports := []tPassport{}
re := regexp.MustCompile(`\n|\s`)
for _, passportRaw := range passportsRaw {
passport := tPassport{}
entries := re.Split(passportRaw, -1)
for _, entry := range entries {
split := strings.Split(entry, ":")
passport[split[0]] = split[1]
}
passports = append(passports, passport)
}
validSimple := 0
validComplex := 0
for _, passport := range passports {
simple, complex := verifyPassport(passport)
if simple {
validSimple++
}
if complex {
validComplex++
}
}
fmt.Println("Simple Validation:\t", validSimple)
fmt.Println("Extended Validation:\t", validComplex)
}

View File

@@ -0,0 +1,52 @@
from os.path import join, dirname
import re
def validate_chunk(chunk, extended=False):
parts = re.split(' |\n', chunk.strip())
password = dict(map(lambda p: p.split(":"), parts))
required = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid']
if not all(item in password.keys() for item in required):
return False
if not extended:
return True
if not 1920 <= int(password['byr']) <= 2002:
return False
if not 2010 <= int(password['iyr']) <= 2020:
return False
if not 2020 <= int(password['eyr']) <= 2030:
return False
tmp = password['hgt']
hgt = int(tmp[:-2])
unit = tmp[-2:]
if not unit in ['cm', 'in']:
return False
if unit == 'cm' and not 150 <= hgt <= 193:
return False
if unit == 'in' and not 59 <= hgt <= 76:
return False
if not re.match(r'^#[\dabcdef]{6}$', password['hcl']):
return False
if not re.match(r'^\d{9}$', password['pid']):
return False
if password['ecl'] not in ['amb', 'blu', 'brn', 'gry', 'grn', 'hzl', 'oth']:
return False
return True
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
chunks = re.split('\n\n+', f.read().strip())
total_simple = 0
total_extended = 0
for chunk in chunks:
total_simple += int(validate_chunk(chunk))
total_extended += int(validate_chunk(chunk, extended=True))
print(f'Simple Validation:\t{total_simple}')
print(f'Extended Validation:\t{total_extended}')

13
2020/solutions/4/test.txt Normal file
View File

@@ -0,0 +1,13 @@
ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
byr:1937 iyr:2017 cid:147 hgt:183cm
iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
hcl:#cfa07d byr:1929
hcl:#ae17e1 iyr:2013
eyr:2024
ecl:brn pid:760753108 byr:1931
hgt:179cm
hcl:#cfa07d eyr:2025 pid:166559648
iyr:2011 ecl:brn hgt:59in

View File

@@ -0,0 +1,13 @@
# 5
For the first one we treat the codes as 2 binary codes. One 7 and the other 3 long.
The second tripped me up as I was returning the binary encoded ticket number but AOC was expecting the seat ID. My bad, took me long to get it. Thanks to @tcq1
<details>
<summary>Solutions</summary>
<ol>
<li>998</li>
<li>84, 4 -> 676</li>
</ol>
</details>

960
2020/solutions/5/data.txt Normal file
View File

@@ -0,0 +1,960 @@
BFBBBBBLLR
BBFFBBFRRL
FBFBFFFRRL
BBFFFBFRRL
BFFBFBFRLL
FFBBBFBLRL
BFFFBFFLLR
FBFFFFBLRR
FBFFBBBRRR
BFFBFFFLLR
BFFFFFBLLL
FFBBFFBLRR
BFFFFFBRLR
FBFBFBFLLL
FFBFBFFLLL
BBFFFFFLLL
FFFBBBFLLL
BBFFBFBLLR
FFBFBFBRRR
BFFBFFFRRR
BBFFBFBRLR
FFFBFBFLRL
BBFFBBBLRR
FBBFFFFLLR
BBBFBBFLLL
BFFFFBBRLL
FBBFBFBRRL
FFBBBFFRRR
BBFFFFBRRR
FBBBBFFLLR
BFFFFFBLRR
FFBBFBFLLR
BFFBFBBLLL
BBFBBBBLLL
FBFBBBFRLL
FFBFFFBLRL
FFFFBBBLRL
BBBBFBFRRR
FFBBFBBRLL
FFFBBBBRRL
FFBFFFBRLR
BFBFBFBLLL
FFFBFFBLLL
BBFBFBBLRL
BBBBBFFLLL
FBBBBFFRRR
FBFFFFBLLL
FFFFBBBRRL
FBFBBBFRRR
FBBFFBFLRL
BFBFFBFLLR
FFBBBFBLLL
BFBFFFFLLL
BBBFFFFLLL
BFBBFBFRLR
BFBBBBFLRL
BBBFBFBLRL
BFFFBFBLRL
BFBBBBBRLL
FBBBFFBRLL
BFBFFBBRRL
BFFBBBFLLR
BFFBFFBRRR
FBFBFBFRRL
FBFBFBFLRL
BBBFFFBRRR
FBFFBBFRRR
FFBBFFFRLL
BFBFBBBLLR
BFFFFBFLLR
FFBBBBFRLR
FFFBFFFRRR
BFBBFFFRLL
BBBFBFFLRL
BFBBFBFLRR
BBBBFBBLRL
FBFBFBFLRR
BBFBFB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FFFRLR
FBBFFFFLLL
FBFBBFFRRR
FBFBBFFLLR
FFBFFFBRRL
BFBBBBFRLL
BFFBBBFLRL
FBFFBFBRRL
FFBFFFFLRR
FBBBFBBRLL
BBFBBBFRRR
BFFBFFFRLL
FFFBBFFRRL
BFBFFFBLLR
FBFFFBFRLR
FBFBBBFLLL
FFBBFBFRRL
BBBFBFFRLL
FBFFBFFLRR
BBFBBBFLRR
FFBBBFBLRR
FFFBFFFRLR
FBFBFFBLLL
BFBBBFFLLL
BFFFFBBLRR
FBFBBBFLLR
FBFFBBFLRR
FFBBFBBRRL
BBFBFFFLRR
BBFFBFFRRL
FFBBFFFLLL
FFBFBFFRRL
BBBFBFBRLR
BFBFFFBRLR
FBFBBBBLLL
FFBBBBBRLL
FBBFBBBLLL
BFFFBBFRRR
BFBFFBFRLR
BBBFFFFRLR
FBFFBBFRLL
FFBBFBFRLR
BFFBFBBRLL
BFBFBFFRRR
FBBFFFBRLL

View File

@@ -0,0 +1,51 @@
from os.path import join, dirname
from itertools import product
from typing import Tuple
def from_binary(code: str, high: str) -> int:
return int(''.join([
'1' if char == high else '0'
for char in code
]), 2)
def read_seat(seat) -> Tuple[int, int]:
row_raw = seat[:-3]
column_raw = seat[-3:]
row = from_binary(row_raw, 'B')
column = from_binary(column_raw, 'R')
return row, column
def seat_code(row: int, column: int) -> int:
return row * 8 + column
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
seats = f.read().strip().split('\n')
free = list(product(range(4, 126), range(8)))
maximum = 0
for seat in seats:
row, column = read_seat(seat)
m = row * 8 + column
maximum = max(maximum, m)
free.remove((row, column))
print(f"Highers ID:\t{maximum}")
# Find the remaining seat
row_max = 0
row_min = 128
for row, _ in free:
row_max = max(row_max, row)
row_min = min(row_min, row)
remaining = [
(row, column)
for row, column in free
if row >= row_min + 1 and row <= row_max - 2
][0]
my_ticket = seat_code(*remaining)
print(f"My Ticket:\t{my_ticket}")

View File

@@ -0,0 +1,4 @@
FBFBBFFRLR
BFFFBBFRRR
FFFBBBFRRR
BBFFBBFRLL

View File

@@ -0,0 +1,13 @@
# 6
Basically I own this one to the built in `set()` of python.
The first is an union, the second an intersection. Did not know they existed
<details>
<summary>Solutions</summary>
<ol>
<li>6809</li>
<li>3394</li>
</ol>
</details>

2246
2020/solutions/6/data.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
from os.path import join, dirname
from itertools import product
from typing import List, Set, Tuple
from functools import reduce
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
groups = f.read().strip().split('\n\n')
at_least_one: List[int] = []
everyone: List[int] = []
for group in groups:
answers: Set[str] = set()
combined = None
for answer in group.split('\n'):
answer = answer.strip()
as_set = set(list(answer))
answers = answers.union(as_set)
combined = as_set if combined == None else combined.intersection(
as_set)
at_least_one.append(len(answers))
everyone.append(len(combined))
# print(single)
# print(reduce(lambda a, b: a.intersection(b), single))
print(f'At least one person: {sum(at_least_one)}')
print(f'Everyone: {sum(everyone)}')

15
2020/solutions/6/test.txt Normal file
View File

@@ -0,0 +1,15 @@
abc
a
b
c
ab
ac
a
a
a
a
b

View File

@@ -0,0 +1,15 @@
# 7
This one was maybe the coolest yet! Fixed-point iteration and some recursion. Amazing :)
For the first part we iterate as long as we don't find any enclosing bags anymore. This can build long chains.
The second we recurse down the bag chain und sum it up recursively.
<details>
<summary>Solutions</summary>
<ol>
<li>164</li>
<li>7872</li>
</ol>
</details>

594
2020/solutions/7/data.txt Normal file
View File

@@ -0,0 +1,594 @@
pale cyan bags contain 2 posh black bags, 4 wavy gold bags, 2 vibrant brown bags.
dull lavender bags contain 3 pale tomato bags.
light red bags contain 3 wavy teal bags, 3 plaid aqua bags, 4 drab lavender bags, 2 bright coral bags.
wavy green bags contain 3 wavy indigo bags.
bright blue bags contain 5 vibrant tan bags.
dotted fuchsia bags contain 5 dark orange bags, 1 shiny coral bag.
pale tomato bags contain 2 bright magenta bags, 5 dull lime bags.
light black bags contain 1 posh lavender bag, 5 dotted gold bags, 4 faded bronze bags.
wavy turquoise bags contain 4 pale teal bags, 2 dim brown bags, 5 muted lime bags.
striped red bags contain 4 faded brown bags, 4 dotted purple bags.
wavy silver bags contain 5 muted chartreuse bags, 1 light silver bag, 3 striped silver bags.
posh lavender bags contain 5 striped silver bags, 3 wavy beige bags, 3 dim brown bags, 5 clear indigo bags.
pale maroon bags contain 1 striped white bag, 4 light blue bags.
drab turquoise bags contain 2 shiny tomato bags.
dark aqua bags contain 2 plaid silver bags.
vibrant coral bags contain 3 wavy lime bags, 2 shiny gold bags, 1 dotted orange bag, 3 muted indigo bags.
clear green bags contain 1 clear olive bag.
striped indigo bags contain 3 striped turquoise bags.
clear lime bags contain 3 mirrored green bags, 2 light tan bags.
drab bronze bags contain 5 plaid lavender bags, 1 muted yellow bag, 5 vibrant coral bags.
drab lavender bags contain 1 posh tomato bag, 4 muted salmon bags, 4 dull lime bags.
striped aqua bags contain 1 pale maroon bag.
wavy gray bags contain 3 light tan bags, 2 pale white bags, 2 bright magenta bags, 5 muted salmon bags.
faded aqua bags contain 1 plaid salmon bag, 4 dotted yellow bags.
drab cyan bags contain 1 posh tomato bag, 4 shiny turquoise bags.
vibrant blue bags contain no other bags.
light lime bags contain 3 vibrant purple bags.
clear gray bags contain 3 mirrored olive bags, 3 clear crimson bags, 5 dark orange bags, 2 dim gold bags.
bright magenta bags contain no other bags.
wavy purple bags contain 4 dim gold bags, 5 light green bags.
muted bronze bags contain 2 pale beige bags, 2 clear turquoise bags, 5 posh white bags, 1 wavy gray bag.
striped violet bags contain 1 light gold bag.
dull salmon bags contain 2 posh gray bags, 2 dotted blue bags.
striped orange bags contain 3 faded coral bags, 3 dotted lavender bags.
drab coral bags contain 1 wavy indigo bag, 1 dull black bag, 3 mirrored chartreuse bags.
plaid yellow bags contain 5 faded cyan bags.
dark maroon bags contain 2 mirrored silver bags, 5 muted salmon bags, 1 dull tomato bag.
dark yellow bags contain 1 drab maroon bag, 5 faded cyan bags, 4 clear indigo bags.
posh teal bags contain 3 vibrant maroon bags, 3 posh salmon bags.
mirrored black bags contain 1 drab fuchsia bag, 2 posh red bags.
drab salmon bags contain 2 dull plum bags.
muted green bags contain 4 plaid gray bags, 2 dim turquoise bags, 2 dull coral bags, 4 dim white bags.
bright indigo bags contain 1 bright turquoise bag, 4 dark beige bags.
wavy fuchsia bags contain 1 clear violet bag, 4 striped bronze bags, 1 mirrored indigo bag, 1 shiny cyan bag.
bright brown bags contain 5 dark purple bags.
dull turquoise bags contain 3 dim yellow bags, 2 dim indigo bags.
pale coral bags contain 4 posh indigo bags.
striped green bags contain 4 dull green bags, 5 dotted turquoise bags, 3 pale red bags, 2 dark gold bags.
faded maroon bags contain 3 dim green bags, 4 wavy purple bags.
vibrant lime bags contain 3 shiny fuchsia bags, 1 pale red bag, 1 vibrant bronze bag.
shiny plum bags contain 2 bright maroon bags, 5 dull tomato bags, 2 plaid salmon bags, 3 bright lime bags.
faded silver bags contain 1 posh turquoise bag, 5 posh white bags, 5 wavy lime bags, 3 shiny coral bags.
mirrored tomato bags contain 3 dotted tomato bags, 4 vibrant blue bags, 4 dull yellow bags, 5 clear chartreuse bags.
pale red bags contain 5 vibrant indigo bags, 4 vibrant red bags, 3 bright magenta bags, 3 dim indigo bags.
drab blue bags contain 2 bright magenta bags.
dim purple bags contain 4 drab lavender bags, 4 plaid yellow bags, 5 dull white bags, 3 clear white bags.
dim red bags contain 5 striped silver bags, 1 shiny red bag.
dim lime bags contain 5 plaid bronze bags, 5 drab salmon bags.
mirrored beige bags contain 3 bright tomato bags, 2 dull lime bags.
bright lime bags contain 5 clear chartreuse bags.
clear chartreuse bags contain 1 muted white bag, 1 vibrant bronze bag, 2 vibrant maroon bags, 4 clear lime bags.
dotted indigo bags contain 4 pale olive bags, 1 bright violet bag, 3 drab gray bags.
striped crimson bags contain 3 muted salmon bags.
plaid green bags contain 3 posh tomato bags.
dim brown bags contain 3 striped teal bags, 3 vibrant aqua bags, 3 plaid yellow bags.
faded turquoise bags contain 2 dim blue bags, 3 clear green bags, 3 striped bronze bags, 2 dim beige bags.
dotted coral bags contain 2 vibrant silver bags, 3 plaid crimson bags, 4 dull silver bags, 1 muted blue bag.
mirrored magenta bags contain 3 striped teal bags, 1 mirrored black bag, 4 shiny black bags.
shiny gray bags contain 3 bright magenta bags.
mirrored violet bags contain 5 drab blue bags, 5 dark brown bags.
dark beige bags contain 2 vibrant blue bags, 2 bright magenta bags, 1 dim indigo bag.
dark bronze bags contain 3 vibrant chartreuse bags, 2 posh turquoise bags, 4 faded aqua bags.
clear turquoise bags contain 1 mirrored green bag, 1 faded indigo bag, 4 shiny aqua bags, 4 dim tomato bags.
dark silver bags contain 5 posh purple bags, 4 dull silver bags.
dull tan bags contain 2 striped brown bags, 3 vibrant salmon bags, 1 drab gold bag.
mirrored gray bags contain 2 dim white bags, 4 muted white bags, 1 muted orange bag, 3 muted magenta bags.
faded black bags contain 3 faded aqua bags, 4 drab white bags, 2 dull lavender bags, 1 bright purple bag.
light fuchsia bags contain 3 pale magenta bags.
wavy lavender bags contain no other bags.
dull black bags contain 1 mirrored teal bag.
vibrant chartreuse bags contain 1 dull violet bag, 4 posh turquoise bags.
posh yellow bags contain 5 wavy gold bags.
shiny teal bags contain 2 drab salmon bags, 5 striped crimson bags.
plaid fuchsia bags contain 3 dim brown bags, 2 posh bronze bags, 1 striped aqua bag, 1 shiny chartreuse bag.
faded yellow bags contain 1 dotted tan bag, 3 dark coral bags.
mirrored orange bags contain 3 pale coral bags.
wavy indigo bags contain 5 shiny coral bags, 2 shiny yellow bags, 2 striped brown bags.
dotted salmon bags contain 1 drab turquoise bag, 1 vibrant lime bag, 3 dull chartreuse bags, 1 vibrant maroon bag.
dull magenta bags contain 3 shiny coral bags, 5 dull violet bags, 5 mirrored violet bags.
shiny tomato bags contain 1 dim salmon bag, 1 dim olive bag.
drab gold bags contain 3 drab maroon bags, 1 dotted black bag, 4 plaid orange bags.
bright yellow bags contain 4 muted teal bags, 1 faded maroon bag, 5 posh chartreuse bags, 5 plaid indigo bags.
dull plum bags contain 1 shiny salmon bag, 3 light tan bags.
posh gray bags contain 3 muted lime bags, 2 dotted green bags.
clear violet bags contain 5 vibrant maroon bags.
dotted bronze bags contain 3 light tan bags, 4 shiny yellow bags, 3 mirrored brown bags, 1 plaid yellow bag.
mirrored lime bags contain 2 bright teal bags, 2 dim gold bags, 2 dull tomato bags, 3 wavy green bags.
shiny indigo bags contain 3 dull silver bags, 2 dim cyan bags, 2 striped magenta bags.
vibrant crimson bags contain 2 light chartreuse bags.
dim magenta bags contain 5 plaid olive bags, 2 muted green bags, 4 bright crimson bags.
dim blue bags contain 1 bright silver bag, 2 shiny gray bags.
plaid teal bags contain 4 shiny aqua bags, 1 dull fuchsia bag, 4 bright lime bags.
dull teal bags contain 2 dotted black bags.
plaid gray bags contain 5 muted brown bags.
pale teal bags contain 5 striped olive bags, 1 dotted fuchsia bag, 3 dark teal bags, 2 dim purple bags.
clear beige bags contain 3 pale lime bags, 4 striped aqua bags, 3 mirrored red bags.
mirrored green bags contain 4 mirrored olive bags, 5 dim salmon bags, 4 vibrant bronze bags.
plaid aqua bags contain 2 pale white bags, 1 dull plum bag, 4 mirrored olive bags, 3 dim maroon bags.
pale aqua bags contain 5 bright salmon bags, 4 vibrant silver bags, 2 light orange bags.
plaid crimson bags contain 3 striped magenta bags.
mirrored red bags contain 5 dull coral bags, 5 pale yellow bags, 5 drab maroon bags, 2 dim gray bags.
pale black bags contain 1 light red bag, 4 faded teal bags.
dim turquoise bags contain 5 faded purple bags, 4 wavy fuchsia bags, 3 vibrant purple bags, 2 pale beige bags.
dim lavender bags contain 1 light blue bag.
pale gray bags contain 3 mirrored red bags, 5 light indigo bags.
clear magenta bags contain 5 bright gold bags, 5 dim lavender bags, 1 wavy lavender bag.
dull gold bags contain 4 dull fuchsia bags, 3 vibrant tan bags.
dim salmon bags contain 5 dull yellow bags, 4 pale beige bags.
drab magenta bags contain 2 vibrant salmon bags.
vibrant green bags contain 3 bright purple bags, 5 wavy brown bags, 5 dotted gray bags, 1 posh bronze bag.
dull brown bags contain 1 wavy tan bag, 1 shiny salmon bag.
clear white bags contain 5 bright lime bags, 3 light tan bags.
dotted lavender bags contain 5 wavy cyan bags, 2 dark indigo bags, 4 shiny gold bags.
dotted purple bags contain 5 dull teal bags, 3 shiny plum bags.
drab yellow bags contain 3 faded beige bags, 3 light silver bags.
dark orange bags contain 5 bright lime bags.
dotted cyan bags contain 1 vibrant lime bag, 1 wavy maroon bag, 2 dull tan bags, 5 shiny salmon bags.
posh indigo bags contain 5 dull yellow bags, 1 vibrant bronze bag.
dull chartreuse bags contain 2 wavy lavender bags, 5 vibrant blue bags.
posh blue bags contain 3 wavy maroon bags.
dim teal bags contain 3 muted turquoise bags, 1 vibrant black bag, 5 dotted tomato bags.
pale purple bags contain 1 striped olive bag.
drab chartreuse bags contain 1 clear orange bag, 2 plaid turquoise bags, 2 drab maroon bags.
plaid white bags contain 4 plaid indigo bags, 5 vibrant lime bags.
vibrant bronze bags contain 5 vibrant blue bags, 1 drab blue bag, 1 dull lime bag.
bright bronze bags contain 3 muted magenta bags, 3 dotted black bags, 1 pale lime bag, 2 dull violet bags.
dark indigo bags contain 3 bright maroon bags.
muted lavender bags contain 1 light white bag, 2 clear white bags, 2 posh white bags, 3 dim purple bags.
vibrant violet bags contain 5 dull magenta bags, 4 posh coral bags.
drab beige bags contain 2 plaid magenta bags, 2 muted bronze bags, 2 muted purple bags.
drab plum bags contain 4 mirrored tomato bags, 3 light lavender bags, 3 mirrored green bags, 5 muted salmon bags.
mirrored fuchsia bags contain 1 mirrored tomato bag, 5 dotted black bags, 2 posh white bags.
pale crimson bags contain 4 light plum bags.
dotted black bags contain 3 bright maroon bags.
wavy tomato bags contain 1 dim black bag, 5 vibrant coral bags, 1 mirrored purple bag.
bright aqua bags contain 5 pale lime bags, 3 striped teal bags.
vibrant purple bags contain 2 clear turquoise bags, 4 vibrant bronze bags, 1 dark lime bag, 3 clear crimson bags.
vibrant tan bags contain 4 posh black bags.
plaid turquoise bags contain 2 dotted violet bags, 5 mirrored plum bags.
dim violet bags contain 3 dotted orange bags.
bright tan bags contain 2 dark indigo bags, 4 faded purple bags, 4 dim blue bags.
muted chartreuse bags contain 4 dotted black bags, 5 mirrored tomato bags.
muted gold bags contain 2 wavy gray bags, 4 clear gold bags, 1 shiny gold bag.
dull indigo bags contain 3 mirrored maroon bags.
clear aqua bags contain 4 dim plum bags, 5 bright bronze bags.
muted maroon bags contain 1 striped crimson bag, 3 vibrant aqua bags.
muted blue bags contain 4 clear magenta bags, 4 pale bronze bags, 2 dull black bags, 4 striped olive bags.
drab aqua bags contain 3 faded crimson bags.
shiny olive bags contain 4 shiny salmon bags, 2 wavy plum bags, 4 pale bronze bags, 3 posh gold bags.
striped bronze bags contain 4 plaid olive bags, 4 plaid indigo bags, 1 pale white bag, 3 striped magenta bags.
mirrored gold bags contain 2 faded lavender bags.
faded blue bags contain 1 plaid bronze bag, 3 dim olive bags, 2 wavy crimson bags, 4 plaid silver bags.
plaid lime bags contain 2 dim yellow bags.
mirrored brown bags contain 4 light crimson bags.
plaid red bags contain 5 shiny aqua bags, 5 wavy lavender bags, 1 posh beige bag.
mirrored coral bags contain 4 mirrored lime bags, 5 muted orange bags, 5 dotted salmon bags, 1 faded purple bag.
mirrored olive bags contain 2 vibrant blue bags.
pale orange bags contain 4 wavy lime bags.
drab maroon bags contain 1 shiny yellow bag, 3 dull yellow bags, 1 wavy lavender bag, 2 dim salmon bags.
drab purple bags contain 5 bright tomato bags, 4 striped bronze bags, 2 bright chartreuse bags, 2 dark violet bags.
striped lime bags contain 5 posh turquoise bags, 1 dim purple bag.
wavy beige bags contain 5 shiny tomato bags, 3 drab lavender bags, 1 shiny orange bag.
bright gold bags contain 5 vibrant red bags, 1 shiny orange bag, 3 striped bronze bags.
muted magenta bags contain 4 light olive bags, 3 dotted tan bags.
dark lime bags contain 5 wavy lavender bags, 4 clear maroon bags, 2 striped beige bags, 4 plaid salmon bags.
pale silver bags contain 3 faded lavender bags, 2 dotted purple bags, 3 wavy crimson bags.
posh turquoise bags contain 5 dim yellow bags, 4 posh lime bags, 5 shiny orange bags.
shiny coral bags contain 2 dull tomato bags.
dim tomato bags contain 3 shiny aqua bags, 3 light cyan bags.
plaid tomato bags contain 3 faded indigo bags.
clear tan bags contain 3 mirrored indigo bags.
wavy maroon bags contain 1 dark silver bag.
drab teal bags contain 5 muted salmon bags, 4 plaid yellow bags, 4 bright red bags, 2 posh teal bags.
dim plum bags contain 5 posh salmon bags, 5 faded purple bags, 2 posh brown bags.
bright fuchsia bags contain 2 dark beige bags, 3 faded yellow bags.
clear silver bags contain 2 plaid tomato bags, 4 muted chartreuse bags.
shiny purple bags contain 5 muted lavender bags, 2 clear turquoise bags, 4 muted teal bags.
dark red bags contain 3 plaid plum bags, 2 dim indigo bags, 2 wavy gray bags.
dark white bags contain 4 muted bronze bags, 5 mirrored gold bags, 3 plaid lavender bags.
drab silver bags contain 1 dark gold bag, 3 muted white bags.
dark green bags contain 3 posh turquoise bags.
striped white bags contain 1 vibrant maroon bag, 1 shiny salmon bag.
striped lavender bags contain 1 light tomato bag, 5 light lime bags, 1 posh gold bag.
mirrored tan bags contain 2 posh fuchsia bags.
pale salmon bags contain 4 shiny blue bags.
dark black bags contain 1 dotted coral bag, 1 faded crimson bag, 4 drab violet bags, 5 clear chartreuse bags.
vibrant red bags contain 1 dim gold bag, 2 dull yellow bags, 1 faded brown bag, 4 light cyan bags.
pale turquoise bags contain 5 clear cyan bags.
bright olive bags contain 1 clear turquoise bag, 4 bright teal bags, 3 striped maroon bags, 1 striped gold bag.
shiny green bags contain 5 dim lime bags, 3 wavy brown bags, 2 faded magenta bags, 5 drab maroon bags.
vibrant tomato bags contain 3 striped plum bags, 2 vibrant maroon bags, 4 muted silver bags, 3 striped chartreuse bags.
vibrant yellow bags contain 3 pale beige bags, 4 dim orange bags, 4 dotted cyan bags.
muted aqua bags contain 3 vibrant purple bags.
dull orange bags contain 2 striped gray bags, 3 vibrant bronze bags, 2 bright turquoise bags.
wavy cyan bags contain 2 drab maroon bags, 4 shiny aqua bags, 5 clear lime bags.
faded tan bags contain 3 muted turquoise bags, 2 plaid purple bags, 3 clear crimson bags.
light maroon bags contain 5 wavy chartreuse bags, 3 mirrored silver bags, 5 muted plum bags, 2 mirrored blue bags.
shiny lavender bags contain 1 dark silver bag, 5 clear teal bags, 5 dark red bags, 4 faded red bags.
striped fuchsia bags contain 4 clear gold bags, 3 bright magenta bags, 3 bright aqua bags.
striped plum bags contain 4 bright lime bags, 5 dotted black bags, 5 drab beige bags.
dotted red bags contain 4 dim gold bags, 3 dim indigo bags, 4 striped olive bags, 5 dim white bags.
mirrored chartreuse bags contain 5 posh tomato bags.
dim white bags contain 5 clear maroon bags.
muted black bags contain 2 posh turquoise bags, 3 clear lavender bags, 2 shiny aqua bags, 2 pale red bags.
muted silver bags contain 4 striped white bags, 5 dotted tomato bags, 4 mirrored fuchsia bags, 2 clear maroon bags.
dotted lime bags contain 1 muted aqua bag, 3 mirrored tan bags.
faded chartreuse bags contain 4 vibrant violet bags, 5 faded magenta bags, 5 dim teal bags, 2 dim green bags.
light turquoise bags contain 1 dotted purple bag.
plaid cyan bags contain 1 bright magenta bag, 2 wavy chartreuse bags, 5 vibrant silver bags, 3 pale crimson bags.
dull maroon bags contain 5 dim black bags.
wavy violet bags contain 1 faded yellow bag.
vibrant teal bags contain 5 dim lime bags, 2 vibrant gold bags, 2 dim beige bags.
pale fuchsia bags contain 3 striped olive bags.
light brown bags contain 3 shiny chartreuse bags, 2 wavy purple bags.
dull green bags contain 3 striped orange bags, 2 posh indigo bags, 3 faded blue bags.
dark blue bags contain 5 striped magenta bags, 3 striped gray bags, 4 pale coral bags.
mirrored lavender bags contain 3 posh black bags.
shiny brown bags contain 5 dotted magenta bags, 4 dim chartreuse bags, 1 posh cyan bag.
muted brown bags contain 3 dull black bags, 3 pale maroon bags, 5 posh brown bags, 2 striped gray bags.
faded orange bags contain 1 dark orange bag.
muted fuchsia bags contain 3 plaid salmon bags.
clear plum bags contain 3 shiny red bags, 4 dim silver bags.
bright coral bags contain 4 pale yellow bags, 2 muted magenta bags, 2 bright chartreuse bags, 3 light olive bags.
muted coral bags contain 4 striped green bags.
drab olive bags contain 3 shiny salmon bags, 4 clear cyan bags.
dim silver bags contain 2 shiny plum bags.
wavy plum bags contain 3 mirrored fuchsia bags, 5 pale maroon bags, 5 posh salmon bags.
plaid coral bags contain 1 mirrored gold bag.
posh beige bags contain 3 mirrored maroon bags, 3 drab chartreuse bags, 3 dark salmon bags, 1 clear green bag.
drab green bags contain 1 bright teal bag, 3 muted chartreuse bags.
bright crimson bags contain 3 striped orange bags, 4 wavy plum bags.
posh chartreuse bags contain 5 clear white bags, 3 light red bags.
dim gray bags contain 1 mirrored fuchsia bag, 3 muted teal bags, 4 clear maroon bags, 5 striped white bags.
striped brown bags contain 2 muted orange bags.
dim tan bags contain 3 clear gold bags, 5 clear salmon bags, 2 dark chartreuse bags.
striped magenta bags contain 2 plaid indigo bags, 5 drab lavender bags, 2 dotted fuchsia bags, 4 shiny aqua bags.
dotted violet bags contain 3 dull tomato bags.
dotted tan bags contain 1 dark orange bag, 2 drab blue bags.
shiny beige bags contain 1 drab gold bag.
light plum bags contain 5 plaid tomato bags, 5 wavy gray bags, 1 dull tomato bag.
muted indigo bags contain 3 dim salmon bags.
clear red bags contain 3 mirrored beige bags.
mirrored silver bags contain 2 wavy plum bags, 4 vibrant magenta bags.
dark lavender bags contain 2 wavy violet bags, 5 muted green bags, 2 dim purple bags.
clear teal bags contain 4 wavy crimson bags.
light purple bags contain 5 faded black bags.
light salmon bags contain 3 vibrant beige bags, 3 striped white bags, 5 pale magenta bags, 5 muted blue bags.
dull gray bags contain 5 dim lavender bags.
posh aqua bags contain 1 light olive bag, 4 mirrored purple bags, 4 vibrant gold bags, 1 shiny aqua bag.
pale chartreuse bags contain 5 faded indigo bags.
striped cyan bags contain 1 shiny olive bag, 3 bright tomato bags, 1 faded beige bag.
clear coral bags contain 5 clear violet bags, 1 plaid tomato bag.
bright cyan bags contain 3 mirrored violet bags, 5 plaid magenta bags, 4 vibrant bronze bags.
posh tomato bags contain 3 shiny aqua bags, 1 pale beige bag.
bright lavender bags contain 4 clear beige bags, 2 faded lavender bags, 3 faded aqua bags, 5 pale purple bags.
dotted teal bags contain 5 plaid salmon bags, 1 posh turquoise bag, 2 muted silver bags.
clear tomato bags contain 5 bright indigo bags.
dotted silver bags contain 2 mirrored indigo bags.
plaid plum bags contain 4 light crimson bags.
wavy magenta bags contain 2 posh indigo bags, 2 vibrant indigo bags.
dull tomato bags contain 4 dull lime bags, 4 faded brown bags.
vibrant black bags contain 5 light crimson bags, 5 pale lavender bags, 3 dull blue bags, 2 pale coral bags.
pale bronze bags contain 3 vibrant violet bags.
wavy lime bags contain 5 shiny yellow bags, 2 pale white bags, 1 clear gold bag, 5 mirrored chartreuse bags.
striped gray bags contain 3 shiny tomato bags, 3 dull coral bags, 1 shiny aqua bag, 2 dark orange bags.
faded crimson bags contain 4 pale white bags, 3 muted bronze bags, 2 posh blue bags, 3 bright coral bags.
wavy orange bags contain 2 shiny indigo bags.
dotted white bags contain 1 striped tan bag, 4 bright silver bags, 1 shiny fuchsia bag, 3 posh gray bags.
posh bronze bags contain 4 muted silver bags, 1 light lavender bag.
dotted magenta bags contain 5 clear fuchsia bags, 4 faded indigo bags, 3 dull turquoise bags, 4 muted orange bags.
dull cyan bags contain 3 clear teal bags, 3 dim white bags, 3 dull tomato bags, 5 vibrant purple bags.
clear gold bags contain 4 dim gold bags, 3 dull lime bags, 4 faded brown bags, 4 wavy gray bags.
bright beige bags contain 3 dull cyan bags, 4 bright indigo bags, 2 dull lime bags.
clear orange bags contain 5 shiny salmon bags.
plaid silver bags contain 5 dotted purple bags, 1 dim maroon bag, 3 muted gold bags.
shiny white bags contain 1 light brown bag, 1 mirrored lime bag.
dark gray bags contain 5 shiny cyan bags, 2 drab tomato bags.
drab white bags contain 4 shiny tomato bags, 3 shiny gold bags, 3 dull lime bags, 3 plaid orange bags.
vibrant cyan bags contain 2 wavy purple bags, 4 light gold bags, 1 pale indigo bag, 2 striped fuchsia bags.
shiny yellow bags contain 4 shiny aqua bags, 2 dim salmon bags, 3 posh tomato bags, 5 muted salmon bags.
posh coral bags contain 2 striped gray bags, 4 dark orange bags, 5 posh magenta bags.
clear salmon bags contain 4 posh yellow bags, 2 pale violet bags, 3 mirrored violet bags.
posh olive bags contain 2 mirrored red bags, 3 faded gold bags.
faded fuchsia bags contain 5 bright gold bags, 3 pale tomato bags, 2 dotted bronze bags, 1 mirrored green bag.
striped maroon bags contain 4 posh maroon bags, 4 dim indigo bags, 5 shiny aqua bags, 4 posh lime bags.
dark violet bags contain 5 plaid tomato bags, 3 bright lime bags, 4 light lavender bags, 4 dark brown bags.
dim maroon bags contain 1 dark beige bag, 4 wavy gray bags, 5 shiny coral bags, 1 pale white bag.
wavy crimson bags contain 1 light tan bag, 5 dark beige bags.
plaid magenta bags contain 1 shiny turquoise bag, 1 dark lime bag, 5 dim salmon bags.
clear indigo bags contain 4 muted maroon bags.
clear olive bags contain 5 mirrored teal bags, 1 plaid lime bag, 3 dull magenta bags, 5 wavy gray bags.
mirrored white bags contain 3 pale gold bags.
wavy blue bags contain 1 dotted aqua bag, 5 dark green bags.
faded cyan bags contain 4 wavy gray bags, 5 vibrant bronze bags, 1 mirrored olive bag, 3 drab blue bags.
faded gray bags contain 2 drab brown bags, 4 dotted coral bags, 5 dim turquoise bags, 1 mirrored maroon bag.
dim coral bags contain 5 shiny olive bags, 3 light plum bags.
vibrant fuchsia bags contain 5 shiny chartreuse bags, 5 wavy bronze bags, 2 bright red bags.
dotted tomato bags contain 5 faded indigo bags, 3 vibrant maroon bags, 4 shiny coral bags.
faded salmon bags contain 3 dull silver bags, 2 wavy bronze bags, 2 drab teal bags.
vibrant orange bags contain 1 dotted beige bag.
muted violet bags contain 5 posh lime bags.
striped tan bags contain 3 muted lime bags.
drab violet bags contain 3 vibrant chartreuse bags, 5 posh turquoise bags, 1 bright cyan bag.
bright purple bags contain 2 vibrant bronze bags, 3 wavy beige bags, 2 plaid bronze bags.
vibrant maroon bags contain no other bags.
muted teal bags contain 2 bright turquoise bags.
bright plum bags contain 5 dark gold bags, 2 shiny turquoise bags, 1 dull yellow bag.
shiny crimson bags contain 3 wavy magenta bags.
wavy teal bags contain 5 faded indigo bags, 4 dotted gray bags, 3 pale chartreuse bags, 3 vibrant coral bags.
shiny blue bags contain 2 shiny salmon bags, 4 light tan bags, 1 dim salmon bag.
mirrored maroon bags contain 1 drab fuchsia bag, 3 dotted green bags, 3 muted white bags.
clear maroon bags contain 2 vibrant red bags, 5 bright maroon bags, 4 light olive bags.
bright salmon bags contain 1 dotted red bag, 4 vibrant beige bags, 3 dark maroon bags, 3 clear lavender bags.
pale gold bags contain 3 plaid olive bags.
faded lime bags contain 3 faded maroon bags, 5 mirrored aqua bags.
faded magenta bags contain 4 plaid orange bags, 5 vibrant violet bags, 1 dotted green bag, 3 wavy crimson bags.
wavy aqua bags contain 5 drab yellow bags, 5 posh bronze bags.
faded brown bags contain 3 mirrored green bags, 5 dim salmon bags, 4 vibrant blue bags, 1 wavy gray bag.
dark purple bags contain 4 pale beige bags, 3 drab lavender bags.
dull lime bags contain no other bags.
light orange bags contain 1 vibrant white bag, 1 striped magenta bag.
mirrored plum bags contain 1 clear green bag, 4 faded blue bags.
vibrant brown bags contain 4 dark crimson bags, 5 light plum bags.
shiny turquoise bags contain 1 dark lime bag.
dark plum bags contain 2 wavy coral bags, 2 striped gray bags, 4 muted blue bags, 2 dull aqua bags.
shiny red bags contain 1 plaid gray bag, 4 wavy beige bags, 5 dark red bags.
posh violet bags contain 5 striped chartreuse bags, 2 pale maroon bags, 1 dull lime bag.
light silver bags contain 2 clear silver bags, 1 dark indigo bag, 2 dim salmon bags, 2 drab salmon bags.
plaid orange bags contain 4 dim gold bags, 2 bright magenta bags, 4 drab lavender bags.
vibrant silver bags contain 5 posh plum bags, 3 vibrant aqua bags, 2 light lavender bags.
faded tomato bags contain 1 pale coral bag, 2 posh gold bags.
shiny silver bags contain 4 faded orange bags, 1 striped white bag, 2 faded turquoise bags, 5 striped gray bags.
plaid purple bags contain 2 posh olive bags, 3 pale maroon bags, 3 pale gold bags, 1 faded white bag.
light tomato bags contain 2 vibrant indigo bags, 4 dark orange bags, 5 muted bronze bags, 4 plaid tomato bags.
dull aqua bags contain 5 bright lime bags.
drab red bags contain 5 posh teal bags.
dotted gray bags contain 2 vibrant salmon bags, 4 mirrored chartreuse bags, 1 dotted tomato bag, 4 posh magenta bags.
dull bronze bags contain 3 mirrored brown bags.
shiny aqua bags contain no other bags.
dim gold bags contain no other bags.
pale blue bags contain 4 posh gray bags.
faded purple bags contain 5 shiny blue bags, 5 plaid salmon bags, 4 pale tomato bags, 2 dark gold bags.
striped teal bags contain 4 mirrored green bags.
shiny orange bags contain 4 faded lavender bags, 2 muted salmon bags, 2 dim indigo bags.
wavy yellow bags contain 5 clear silver bags, 2 shiny brown bags.
vibrant turquoise bags contain 1 vibrant magenta bag, 4 dull fuchsia bags, 5 mirrored green bags.
dark teal bags contain 5 dim tomato bags.
posh brown bags contain 3 dark orange bags.
vibrant gray bags contain 2 dark beige bags, 2 wavy teal bags, 3 light purple bags.
drab black bags contain 1 mirrored maroon bag, 3 pale silver bags, 3 dark brown bags, 1 shiny gray bag.
light blue bags contain 2 dim olive bags, 2 striped magenta bags.
muted turquoise bags contain 3 dim lime bags, 3 shiny coral bags.
faded red bags contain 5 clear gray bags.
bright chartreuse bags contain 4 plaid teal bags, 5 drab salmon bags, 5 wavy cyan bags.
light magenta bags contain 5 light aqua bags, 4 light crimson bags, 3 dark yellow bags, 1 light tomato bag.
striped coral bags contain 3 mirrored white bags.
shiny maroon bags contain 1 vibrant red bag, 3 bright red bags.
striped yellow bags contain 1 bright orange bag, 2 faded plum bags, 3 light olive bags, 3 shiny aqua bags.
dull olive bags contain 2 posh fuchsia bags, 2 dull coral bags, 2 faded red bags.
dotted yellow bags contain 1 drab salmon bag, 3 pale fuchsia bags.
light bronze bags contain 3 drab cyan bags, 5 mirrored orange bags, 4 plaid crimson bags.
shiny chartreuse bags contain 1 wavy cyan bag, 4 shiny tomato bags.
dull yellow bags contain no other bags.
faded plum bags contain 5 vibrant blue bags, 5 clear indigo bags, 5 posh teal bags, 4 posh plum bags.
wavy salmon bags contain 4 striped teal bags, 3 wavy tan bags, 1 clear white bag.
posh salmon bags contain 4 dull chartreuse bags, 4 shiny yellow bags, 2 dotted black bags, 3 clear lime bags.
dull white bags contain 2 dim olive bags, 4 vibrant bronze bags, 4 faded cyan bags.
shiny gold bags contain 5 bright maroon bags, 5 shiny aqua bags, 2 clear lime bags, 2 muted white bags.
posh plum bags contain 4 posh purple bags, 2 wavy beige bags, 5 plaid plum bags.
shiny magenta bags contain 4 shiny tan bags, 2 dull green bags, 3 mirrored purple bags.
wavy olive bags contain 4 vibrant olive bags, 2 clear fuchsia bags, 1 light plum bag, 2 dark violet bags.
muted lime bags contain 4 posh white bags, 4 shiny tomato bags.
light indigo bags contain 2 clear turquoise bags, 3 vibrant black bags, 3 striped lime bags.
muted yellow bags contain 3 mirrored tomato bags.
faded beige bags contain 5 clear red bags, 3 dull brown bags, 4 dark red bags, 1 vibrant magenta bag.
striped turquoise bags contain 2 bright aqua bags, 5 dim cyan bags, 1 pale lavender bag.
pale beige bags contain no other bags.
dull silver bags contain 3 bright lime bags, 2 pale tomato bags, 3 mirrored green bags.
clear cyan bags contain 1 vibrant blue bag, 2 faded cyan bags, 1 faded brown bag.
posh green bags contain 2 vibrant gray bags, 1 pale magenta bag.
muted beige bags contain 2 drab blue bags, 3 vibrant magenta bags, 5 pale tomato bags.
bright silver bags contain 4 dull brown bags, 4 vibrant violet bags, 4 dim violet bags.
mirrored bronze bags contain 2 bright indigo bags, 3 shiny coral bags.
dull red bags contain 4 dull plum bags, 1 striped black bag, 1 dim teal bag, 4 dim white bags.
dim chartreuse bags contain 3 drab maroon bags.
drab crimson bags contain 5 dull turquoise bags, 3 posh gold bags, 4 bright gold bags, 2 muted indigo bags.
wavy brown bags contain 1 muted white bag.
plaid violet bags contain 2 faded tomato bags.
muted salmon bags contain 1 light cyan bag, 1 vibrant blue bag.
mirrored salmon bags contain 1 dotted green bag, 2 plaid salmon bags.
posh lime bags contain 1 vibrant blue bag.
shiny tan bags contain 2 bright red bags, 1 dim maroon bag, 3 vibrant salmon bags.
vibrant aqua bags contain 5 shiny orange bags, 2 dull coral bags, 4 vibrant bronze bags, 5 dark indigo bags.
posh magenta bags contain 5 dim maroon bags, 2 wavy indigo bags.
posh red bags contain 4 dull black bags, 2 shiny tomato bags, 4 faded beige bags.
mirrored indigo bags contain 4 faded magenta bags, 1 light red bag, 3 muted gray bags, 2 plaid lavender bags.
drab indigo bags contain 4 dull tan bags, 2 dark coral bags.
vibrant lavender bags contain 5 posh turquoise bags, 4 posh bronze bags, 5 light tomato bags.
mirrored blue bags contain 1 striped bronze bag, 4 plaid salmon bags, 3 posh lime bags, 4 mirrored green bags.
plaid blue bags contain 4 bright violet bags, 5 clear red bags.
dark tan bags contain 3 faded chartreuse bags, 1 posh gold bag, 5 light chartreuse bags.
bright teal bags contain 3 pale yellow bags, 1 vibrant white bag, 3 shiny salmon bags, 1 plaid indigo bag.
dark gold bags contain 1 mirrored green bag.
plaid beige bags contain 5 dim cyan bags.
pale plum bags contain 4 striped olive bags, 1 mirrored violet bag.
drab orange bags contain 1 plaid cyan bag, 2 vibrant green bags, 4 striped crimson bags, 2 posh teal bags.
faded teal bags contain 4 muted salmon bags, 1 dim tomato bag, 5 clear white bags.
posh cyan bags contain 3 shiny gray bags, 2 posh indigo bags.
plaid tan bags contain 4 plaid silver bags, 2 dark beige bags, 3 plaid salmon bags, 5 light beige bags.
muted olive bags contain 5 vibrant salmon bags, 2 dull orange bags.
muted tan bags contain 5 wavy gold bags, 2 striped orange bags, 4 plaid lavender bags.
posh tan bags contain 3 shiny lavender bags, 5 vibrant red bags, 4 light bronze bags.
bright tomato bags contain 3 dull lime bags, 3 wavy gray bags.
dark turquoise bags contain 3 vibrant coral bags, 4 wavy beige bags.
faded indigo bags contain 4 wavy gray bags.
clear blue bags contain 2 pale yellow bags.
light gold bags contain 5 light olive bags, 4 clear white bags, 3 plaid silver bags, 2 bright maroon bags.
light lavender bags contain 2 dotted black bags, 4 plaid tomato bags, 4 dark orange bags, 5 shiny blue bags.
faded coral bags contain 5 pale gold bags, 4 dull black bags.
vibrant salmon bags contain 2 faded teal bags, 4 drab lavender bags, 5 clear teal bags, 1 dim olive bag.
muted orange bags contain 1 posh salmon bag, 2 light cyan bags, 5 shiny tomato bags, 4 dim olive bags.
clear black bags contain 3 wavy bronze bags, 4 wavy lime bags, 4 shiny black bags.
pale violet bags contain 1 faded violet bag, 3 pale chartreuse bags, 5 drab blue bags.
dotted plum bags contain 2 muted chartreuse bags, 3 vibrant turquoise bags, 5 posh brown bags.
plaid maroon bags contain 1 posh coral bag, 1 dull fuchsia bag.
dotted brown bags contain 1 posh lime bag, 5 dull turquoise bags.
pale green bags contain 3 drab magenta bags, 4 dim salmon bags, 1 vibrant chartreuse bag.
dark tomato bags contain 2 clear indigo bags, 1 light plum bag, 2 dull turquoise bags.
striped silver bags contain 5 dark red bags, 4 faded purple bags.
shiny fuchsia bags contain 2 dark gold bags, 3 dull tomato bags.
mirrored aqua bags contain 5 dark bronze bags.
dim beige bags contain 5 dull white bags.
dark chartreuse bags contain 4 light crimson bags, 3 dim salmon bags, 2 dark orange bags.
plaid chartreuse bags contain 4 drab blue bags.
dim green bags contain 4 muted bronze bags, 1 shiny indigo bag.
mirrored crimson bags contain 5 wavy fuchsia bags, 2 vibrant magenta bags.
clear yellow bags contain 3 plaid bronze bags, 1 light tan bag.
bright turquoise bags contain 3 shiny salmon bags.
drab brown bags contain 1 vibrant fuchsia bag.
dim bronze bags contain 2 dim aqua bags, 4 dim beige bags.
dim black bags contain 1 posh purple bag, 4 mirrored bronze bags, 5 posh plum bags.
plaid gold bags contain 4 posh silver bags, 5 light turquoise bags, 3 vibrant black bags.
drab lime bags contain 1 muted gold bag, 4 dotted red bags.
bright red bags contain 1 dull yellow bag, 4 mirrored gold bags.
vibrant white bags contain 2 dull lime bags, 2 faded indigo bags, 1 faded brown bag, 1 muted salmon bag.
drab fuchsia bags contain 3 pale beige bags, 3 dark orange bags.
striped tomato bags contain 1 dark lime bag, 5 dull coral bags.
faded green bags contain 2 wavy blue bags.
vibrant olive bags contain 3 bright tomato bags, 4 wavy beige bags.
dark coral bags contain 5 faded teal bags, 1 mirrored tomato bag, 3 dark orange bags, 5 plaid lime bags.
bright violet bags contain 4 dark lime bags.
wavy tan bags contain 4 light tan bags, 3 vibrant red bags, 2 mirrored olive bags.
dotted beige bags contain 5 striped gray bags, 4 posh plum bags, 1 bright turquoise bag, 4 striped fuchsia bags.
dotted turquoise bags contain 3 mirrored green bags, 4 posh gold bags, 5 drab plum bags.
striped beige bags contain 1 clear gold bag, 1 vibrant white bag, 3 faded cyan bags, 2 shiny gold bags.
posh silver bags contain 2 vibrant gold bags, 2 mirrored violet bags.
mirrored purple bags contain 2 dim yellow bags, 2 dull tomato bags.
shiny lime bags contain 4 clear olive bags, 4 mirrored silver bags, 1 muted tomato bag.
muted cyan bags contain 1 posh coral bag, 5 drab blue bags, 4 wavy lavender bags.
light aqua bags contain 1 dark orange bag.
shiny cyan bags contain 2 dark maroon bags, 5 shiny salmon bags, 5 muted salmon bags, 2 wavy bronze bags.
posh white bags contain 1 posh fuchsia bag.
vibrant plum bags contain 4 light crimson bags.
dotted blue bags contain 1 shiny tan bag, 3 light plum bags, 5 dotted gray bags.
posh maroon bags contain 5 mirrored violet bags.
dull violet bags contain 1 faded teal bag, 2 wavy cyan bags, 3 dull silver bags, 3 vibrant red bags.
posh gold bags contain 4 muted salmon bags, 4 dull plum bags, 3 muted bronze bags.
dim orange bags contain 2 dull coral bags.
dim aqua bags contain 1 drab maroon bag.
striped salmon bags contain 4 muted white bags.
dark cyan bags contain 3 plaid maroon bags.
wavy red bags contain 2 wavy maroon bags, 2 vibrant chartreuse bags, 5 wavy salmon bags.
light yellow bags contain 4 posh lime bags, 1 light white bag.
striped blue bags contain 5 plaid magenta bags, 5 vibrant gold bags.
dark olive bags contain 4 dim maroon bags, 2 shiny tan bags, 5 wavy green bags.
vibrant gold bags contain 1 dull beige bag, 4 posh turquoise bags.
muted white bags contain 1 dim indigo bag, 5 dull lime bags, 5 shiny aqua bags.
light violet bags contain 5 wavy bronze bags.
pale olive bags contain 1 dim gold bag, 2 shiny coral bags.
light gray bags contain 3 bright gold bags.
dim indigo bags contain 3 posh tomato bags, 5 pale tomato bags, 4 shiny aqua bags.
pale indigo bags contain 4 pale bronze bags, 5 light chartreuse bags.
muted red bags contain 3 clear white bags, 4 dull lavender bags, 5 muted purple bags.
plaid olive bags contain 3 dark orange bags, 3 dim gold bags.
dotted maroon bags contain 3 faded purple bags, 5 light green bags.
bright orange bags contain 1 shiny black bag, 2 dim lavender bags, 1 shiny olive bag.
wavy chartreuse bags contain 3 clear lime bags, 4 pale maroon bags.
mirrored turquoise bags contain 2 striped crimson bags, 4 vibrant bronze bags, 5 dotted lavender bags, 2 clear silver bags.
dull purple bags contain 4 posh crimson bags.
faded bronze bags contain 1 clear fuchsia bag, 2 light fuchsia bags, 2 pale chartreuse bags.
clear bronze bags contain 3 pale chartreuse bags, 5 dull tan bags, 1 vibrant tan bag.
vibrant magenta bags contain 4 shiny fuchsia bags, 2 shiny coral bags, 3 faded indigo bags, 4 pale tomato bags.
striped chartreuse bags contain 2 shiny orange bags, 3 mirrored tomato bags, 1 clear lime bag.
dotted green bags contain 1 pale beige bag, 2 mirrored bronze bags, 2 wavy crimson bags.
wavy white bags contain 3 posh magenta bags, 3 muted yellow bags, 3 wavy crimson bags, 4 vibrant olive bags.
muted plum bags contain 4 wavy gold bags.
faded violet bags contain 3 dark violet bags.
dull fuchsia bags contain 4 plaid indigo bags, 1 mirrored brown bag, 5 clear lime bags.
bright green bags contain 3 mirrored white bags, 5 dotted silver bags.
shiny violet bags contain 4 striped salmon bags.
dim fuchsia bags contain 3 striped red bags.
faded lavender bags contain 3 wavy tan bags, 2 clear lime bags.
dim cyan bags contain 4 drab white bags.
dark brown bags contain 5 clear gold bags, 3 vibrant blue bags.
clear lavender bags contain 5 striped turquoise bags, 1 light crimson bag, 5 light tan bags, 2 muted gold bags.
light green bags contain 3 striped silver bags, 4 bright silver bags, 2 light crimson bags.
pale lavender bags contain 5 clear violet bags.
dotted orange bags contain 3 dotted tomato bags, 2 dull plum bags, 5 posh purple bags, 2 drab turquoise bags.
bright black bags contain 3 posh chartreuse bags, 5 wavy indigo bags, 5 dull crimson bags, 2 clear turquoise bags.
dotted gold bags contain 5 striped white bags, 2 striped brown bags, 3 mirrored green bags, 3 dark violet bags.
plaid brown bags contain 3 striped chartreuse bags, 3 striped black bags, 2 bright chartreuse bags.
wavy coral bags contain 3 dim turquoise bags, 4 dim lime bags.
pale brown bags contain 4 dim white bags, 5 bright fuchsia bags, 2 clear orange bags.
mirrored teal bags contain 4 pale lavender bags, 5 vibrant maroon bags, 4 striped gray bags, 4 vibrant indigo bags.
posh orange bags contain 5 posh magenta bags, 4 posh violet bags, 2 plaid magenta bags, 4 muted cyan bags.
dim crimson bags contain 3 drab violet bags, 1 dotted aqua bag.
muted gray bags contain 4 vibrant lime bags, 1 dark maroon bag, 2 clear gold bags, 3 plaid gray bags.
clear brown bags contain 5 shiny tomato bags, 4 striped tan bags, 5 vibrant lavender bags, 1 pale white bag.
posh crimson bags contain 3 dim yellow bags, 4 shiny turquoise bags, 2 vibrant purple bags, 4 mirrored aqua bags.
plaid black bags contain 2 shiny tan bags, 1 pale olive bag, 2 wavy tan bags, 1 clear red bag.
dark crimson bags contain 3 drab fuchsia bags, 5 faded gold bags.
pale tan bags contain 5 posh black bags.
wavy bronze bags contain 1 clear lime bag.
wavy gold bags contain 2 dull lavender bags, 1 bright turquoise bag, 4 striped brown bags, 5 drab turquoise bags.
pale lime bags contain 2 faded cyan bags, 4 muted salmon bags, 4 shiny coral bags, 3 mirrored green bags.
dark magenta bags contain 4 faded chartreuse bags, 1 muted brown bag, 4 vibrant salmon bags, 2 dim indigo bags.
striped purple bags contain 3 mirrored olive bags.
dull crimson bags contain 2 clear orange bags.
dull beige bags contain 1 drab turquoise bag, 1 dark indigo bag, 1 dull white bag.
dotted aqua bags contain 4 dull chartreuse bags.
clear purple bags contain 2 muted beige bags, 3 dull black bags.
light crimson bags contain 1 faded brown bag, 1 vibrant red bag, 4 wavy lavender bags, 1 wavy gray bag.
clear fuchsia bags contain 1 dark maroon bag, 3 muted salmon bags.
muted crimson bags contain 5 light lime bags, 4 posh plum bags, 5 clear fuchsia bags, 1 wavy turquoise bag.
muted purple bags contain 3 dull gray bags, 5 posh gray bags.
shiny salmon bags contain 5 faded brown bags, 4 clear chartreuse bags.
plaid lavender bags contain 1 dim lime bag.
vibrant indigo bags contain 5 dim tomato bags, 2 striped beige bags, 2 mirrored olive bags.
mirrored cyan bags contain 3 plaid coral bags, 5 faded teal bags, 5 pale indigo bags, 3 bright fuchsia bags.
dim yellow bags contain 5 light crimson bags, 1 pale tomato bag.
dotted chartreuse bags contain 3 shiny blue bags.
light beige bags contain 3 bright teal bags, 1 pale tomato bag, 2 light blue bags.
dotted olive bags contain 3 bright indigo bags, 4 muted fuchsia bags.
pale white bags contain 1 vibrant maroon bag, 2 pale tomato bags, 2 bright magenta bags.
mirrored yellow bags contain 2 drab brown bags, 3 striped salmon bags, 4 clear olive bags, 1 dotted black bag.
light olive bags contain 2 bright magenta bags.
muted tomato bags contain 4 shiny lavender bags.
light chartreuse bags contain 5 light plum bags, 4 light olive bags, 3 dark indigo bags.
posh purple bags contain 2 wavy crimson bags.
bright maroon bags contain 4 faded indigo bags.
dull blue bags contain 3 dark brown bags, 3 dim indigo bags, 5 pale silver bags, 1 mirrored brown bag.
light coral bags contain 5 clear teal bags.
bright gray bags contain 3 muted black bags, 3 vibrant cyan bags.
posh fuchsia bags contain 3 clear gold bags, 1 dim salmon bag, 2 shiny salmon bags.
light white bags contain 3 dim cyan bags, 5 clear crimson bags, 3 dull fuchsia bags.
light teal bags contain 3 shiny fuchsia bags, 2 muted white bags, 3 shiny black bags.
plaid salmon bags contain 2 dotted black bags, 2 dark beige bags, 1 shiny coral bag.
wavy black bags contain 5 posh olive bags.
drab gray bags contain 3 mirrored tomato bags, 3 light crimson bags.
dim olive bags contain 5 clear chartreuse bags.
bright white bags contain 2 mirrored tan bags, 1 pale green bag, 5 dull magenta bags, 5 plaid lime bags.
striped olive bags contain 3 muted gold bags.
faded olive bags contain 1 muted indigo bag.
pale yellow bags contain 5 light olive bags, 5 plaid aqua bags, 1 clear white bag, 5 faded purple bags.
dull coral bags contain 4 light crimson bags, 5 shiny aqua bags, 5 wavy cyan bags, 3 dark beige bags.
vibrant beige bags contain 4 striped olive bags, 5 clear gold bags.
dark fuchsia bags contain 1 pale teal bag, 4 dull gray bags.
drab tomato bags contain 4 mirrored white bags.
clear crimson bags contain 4 pale tomato bags, 3 wavy gray bags, 4 drab blue bags, 1 mirrored olive bag.
dotted crimson bags contain 1 plaid crimson bag, 1 dark crimson bag, 1 striped beige bag, 4 pale fuchsia bags.
striped black bags contain 4 muted maroon bags.
shiny bronze bags contain 1 dotted tan bag, 1 vibrant beige bag, 5 faded tomato bags.
light cyan bags contain no other bags.
posh black bags contain 2 dim green bags.
striped gold bags contain 3 drab tan bags.
faded white bags contain 4 pale coral bags.
drab tan bags contain 4 clear gold bags, 5 drab silver bags.
light tan bags contain 2 dull lime bags, 1 muted salmon bag, 4 pale beige bags.
plaid indigo bags contain 3 plaid salmon bags, 1 vibrant maroon bag.
faded gold bags contain 3 dark coral bags.
dark salmon bags contain 5 bright gold bags, 1 pale white bag.
plaid bronze bags contain 3 drab gold bags, 4 dotted black bags.
shiny black bags contain 3 bright magenta bags, 2 dark indigo bags, 1 posh plum bag, 5 drab gold bags.
pale magenta bags contain 1 clear gold bag, 5 posh fuchsia bags, 2 faded cyan bags.

View File

@@ -0,0 +1,70 @@
from os.path import join, dirname
from typing import Dict, List, Set, Tuple
import re
TRules = Dict[str, Dict[str, int]]
def split_trim(input: str, split: str) -> List[str]:
return list(map(lambda s: s.strip(), input.split(split)))
def extract_inner(input: str) -> Tuple[int, str]:
parts = input.split(' ')
amount = int(parts[0])
color = ' '.join(parts[1:-1])
return amount, color
def parse_rules(rules: str) -> TRules:
d: TRules = {}
for rule in rules.strip().split('\n'):
outer, inner = split_trim(rule, 'contain')
outer = re.sub(r'bags?', '', outer).strip()
d[outer] = {
color: amount
for amount, color in [
extract_inner(i)
for i in split_trim(inner, ',')
if 'no other bag' not in i # Also matches "bags"
]
}
return d
def find_enclosing_bags(rules: TRules, color: str) -> Set[str]:
colors: Set[str] = set()
stack: Set[str] = set([color])
while len(stack):
for item in list(stack):
stack.remove(item)
for contains, enclosing in rules.items():
if item in enclosing:
if contains not in colors:
stack.add(contains)
colors.add(contains)
return colors
def count_containing(rules: TRules, color: str) -> int:
children = rules[color]
if not children:
return 0
return sum([
amount + amount * count_containing(rules, clr)
for clr, amount in children.items()
])
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
rules = parse_rules(f.read())
color = 'shiny gold'
first = len(find_enclosing_bags(rules, color))
print(f'We can pack the {color} into {first} bags')
second = count_containing(rules, color)
print(f'We need to put {second} bags into {color}')

View 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.

View File

@@ -0,0 +1,15 @@
# 8
Keep getting better! Today we write a little state machine, love it.
So firstly we remember what `oc` (Operation Counter) we have already visited and if so we simply stop and return the accumulator.
For I basically run the code many times, inverting `nop` to `jmp` and vice versa until i found a working instruction set.
<details>
<summary>Solutions</summary>
<ol>
<li>1087</li>
<li>780</li>
</ol>
</details>

613
2020/solutions/8/data.txt Normal file
View File

@@ -0,0 +1,613 @@
nop +456
nop +38
acc +9
jmp +153
acc +15
nop +560
jmp +452
acc +26
acc +42
jmp +376
acc -5
acc +12
acc -5
jmp +15
jmp +1
acc -9
jmp +533
acc +19
acc +33
acc +34
jmp -6
nop +404
nop +140
acc +0
jmp +123
acc +45
acc +0
jmp +496
jmp +487
acc +9
acc +34
jmp +484
acc +0
acc -14
jmp +466
acc +40
acc +6
acc +30
jmp +444
nop +386
jmp +215
acc +43
acc +5
nop -4
jmp +535
jmp -13
acc +3
acc +7
acc +49
acc -1
jmp +245
acc +9
acc +31
nop +142
jmp +554
acc +3
jmp +493
nop +399
jmp +232
acc -16
acc +33
jmp +410
acc +33
acc +5
acc -17
jmp +272
acc -3
acc +37
jmp +181
jmp -12
nop +344
acc +5
acc -16
jmp +290
nop +530
acc +15
acc +3
jmp +343
acc +2
acc +19
jmp +298
acc +43
acc +25
acc -19
jmp +439
acc +43
acc +45
acc +20
jmp +355
acc +13
acc +24
acc -15
nop +396
jmp +215
acc -7
acc +17
jmp +441
acc -8
acc -19
jmp +505
jmp +282
acc -17
acc -8
acc +20
jmp +359
acc +26
acc +14
acc +47
acc +3
jmp +298
acc +31
nop +205
acc +0
acc +7
jmp +389
acc -5
acc +47
jmp +94
acc -13
jmp +358
acc -13
jmp +134
acc +8
acc -19
jmp +312
acc +43
acc +17
jmp +97
jmp +48
nop +253
acc +48
acc -7
acc -2
jmp +23
acc +26
acc +14
acc -14
acc +17
jmp +18
acc +14
acc +8
jmp +341
acc +35
jmp +227
acc +15
acc -7
jmp -95
acc -19
jmp -59
jmp -31
acc -6
acc -4
acc +24
jmp +84
acc -15
jmp +82
nop +74
acc +8
acc +9
acc +13
jmp +194
jmp +376
acc +34
nop -16
jmp -90
acc +4
acc +43
nop +215
jmp -147
acc +0
acc +11
acc -15
acc +23
jmp +130
acc +40
jmp +106
acc -4
acc -18
acc +18
nop +329
jmp +230
acc +19
nop +172
acc +43
jmp +304
acc +44
nop +213
nop +195
acc +6
jmp -79
acc +41
acc -11
acc +18
acc -9
jmp -25
acc +27
acc -6
acc +31
jmp -56
acc +5
acc +12
acc +32
acc +34
jmp -189
acc +32
acc +5
acc -16
jmp +301
nop +108
nop -108
jmp -141
acc -12
jmp +273
acc +3
jmp +140
acc +7
acc -11
acc -17
nop +194
jmp -122
acc -14
nop +186
acc +24
jmp +277
nop +341
acc +18
jmp -64
acc +45
acc +42
jmp +52
acc +39
nop +91
nop -8
jmp +217
acc +44
acc +15
jmp +72
acc +24
jmp -231
acc -16
nop +55
nop +262
acc +40
jmp +234
jmp -14
acc +31
nop -177
acc +40
jmp +343
acc -8
jmp -169
acc +30
acc +12
acc -11
jmp +41
acc +9
acc -9
jmp +65
acc +38
acc +14
jmp +335
acc -19
acc +38
acc +16
acc -11
jmp +230
jmp -71
acc +48
acc -13
nop -255
jmp +1
jmp -220
acc +2
jmp +157
jmp -105
acc -16
acc -5
jmp -196
acc +30
jmp +139
jmp +83
acc -3
acc -12
jmp +254
jmp -60
acc +33
jmp -37
acc +17
acc -14
jmp +93
nop +178
acc +38
acc +47
jmp -89
jmp +271
acc +43
acc +32
jmp -240
acc +26
acc +32
acc +30
nop +284
jmp +169
acc -7
acc +37
jmp +102
acc +4
jmp +86
jmp -123
acc +0
acc -14
acc +18
jmp +1
jmp -5
jmp -36
jmp +148
acc -17
acc -14
acc +28
acc +15
jmp +79
jmp -289
acc +42
acc -5
acc +13
jmp +240
acc -10
acc -18
acc -16
jmp +103
acc +21
jmp +32
nop +118
acc +22
acc -16
acc +15
jmp -186
acc -2
acc -14
acc +22
acc +16
jmp +73
acc -6
jmp -225
acc -18
nop +113
acc +50
acc -6
jmp +181
acc +41
jmp +1
nop +92
acc +23
jmp +190
acc +39
acc +0
acc +33
jmp +111
nop -63
nop -81
acc +9
acc +35
jmp +50
acc +11
jmp -295
nop +230
acc +34
acc +12
acc +47
jmp +126
acc +0
nop -1
acc +19
acc -16
jmp -360
acc +29
acc -2
jmp -110
acc +2
acc +50
jmp -36
jmp -107
jmp +178
acc -11
jmp +181
nop +115
nop +186
jmp +95
jmp +1
nop +148
acc +2
acc +49
jmp +173
acc +38
jmp +178
acc +28
acc +6
acc +15
jmp +110
acc +49
nop +100
jmp +57
acc +45
nop +65
acc +43
acc +12
jmp -272
jmp -260
nop +100
jmp -224
jmp +142
jmp +52
jmp -34
jmp -110
acc +35
nop -112
jmp +16
jmp -18
jmp -157
jmp +81
acc +1
jmp -107
acc +16
acc +23
jmp -255
acc +22
jmp +42
nop +168
acc +41
jmp -311
jmp -163
jmp +118
nop +4
acc +18
jmp +54
jmp -414
nop -181
acc +10
acc +23
jmp -321
nop -322
acc -9
jmp +101
nop -7
acc +35
acc +46
jmp -312
nop +64
nop -386
jmp -280
acc +16
jmp -156
acc +13
nop -131
jmp +1
jmp -416
jmp +15
jmp -94
jmp -330
nop +93
nop -205
acc +48
jmp -19
jmp -70
nop +21
acc -5
acc +19
jmp +62
acc +22
jmp -448
jmp -77
acc +26
acc -2
jmp +70
acc -2
acc +21
jmp -195
nop -114
jmp +107
acc +37
acc +6
jmp -436
acc +48
jmp +96
jmp -121
acc +0
jmp -74
jmp +1
acc +27
acc +2
jmp -279
acc +7
acc +0
jmp +1
jmp -413
acc +6
jmp -180
acc +18
acc +10
jmp -437
jmp -338
nop -456
jmp -463
acc +1
nop -54
jmp -168
acc +27
jmp -479
acc +42
jmp -408
jmp +85
acc -16
acc +24
jmp -391
jmp -206
nop +8
jmp +1
acc +38
nop -473
jmp -94
acc +10
acc -14
jmp -425
acc +17
nop -208
acc +39
jmp -265
acc +3
jmp -284
acc +19
acc +5
nop -111
acc +22
jmp -309
acc +12
acc +39
jmp -151
acc +33
acc -14
jmp -450
acc +16
nop +50
jmp -188
acc -13
acc +15
acc +4
jmp -484
acc +27
jmp -98
acc +34
jmp -120
jmp -537
acc +43
acc -8
acc -6
jmp -405
acc -8
nop -179
acc -11
jmp -264
acc +24
jmp -280
acc -6
acc +1
jmp -353
acc -18
jmp -58
acc +1
acc -7
acc -2
acc +44
jmp -115
nop -328
acc +27
acc +2
jmp +20
acc +14
acc +34
jmp -460
nop -445
acc -9
acc +24
acc -11
jmp -72
jmp -434
jmp -370
acc +35
acc +43
acc +45
acc +44
jmp -287
jmp -546
nop -474
acc -6
jmp -357
nop -163
nop -218
nop -342
jmp -570
acc +44
acc +4
acc +35
acc +6
jmp -541
jmp -274
acc +48
acc -18
jmp -171
acc -13
acc -14
acc +25
acc +26
jmp +1

View File

@@ -0,0 +1,63 @@
from os.path import join, dirname
from typing import List, Optional, Set, Tuple
Instructions = List[Tuple[str, int]]
class VM:
def __init__(self, code: str) -> None:
instructionsRaw = code.strip().split('\n')
self.acc = 0
self.oc = 0
self.invert: Optional[int] = None
self.instructions: Instructions = []
for instruction in instructionsRaw:
op, value = instruction.split(' ')
self.instructions.append((op, int(value)))
def reset(self):
self.acc = 0
self.oc = 0
def exec(self):
op, value = self.instructions[self.oc]
if self.oc == self.invert:
op = 'jmp' if op == 'nop' else 'nop'
if op == 'nop':
self.oc += 1
elif op == 'acc':
self.acc += value
self.oc += 1
elif op == 'jmp':
self.oc += value
def run(self) -> Tuple[int, bool]:
self.reset()
already_visited: Set[int] = set()
m = len(self.instructions)
while True:
if self.oc in already_visited:
return (self.acc, True)
if not self.oc < m:
return (self.acc, False)
already_visited.add(self.oc)
self.exec()
def fix(self):
for i, instruction in enumerate(self.instructions):
op, _ = instruction
if op == 'nop' or op == 'jmp':
self.invert = i
acc, error = self.run()
if not error:
return acc
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
vm = VM(f.read())
acc, err = vm.run()
print(acc)
print(vm.fix())

View File

@@ -0,0 +1,9 @@
nop +0
acc +1
jmp +4
acc +3
jmp -3
acc -99
acc +1
jmp -4
acc +6

View File

@@ -0,0 +1,11 @@
# 9
Again the python std lib saved me some lines of code. `itertools` to the rescue and basically we are done.
<details>
<summary>Solutions</summary>
<ol>
<li>23278925</li>
<li>4011064</li>
</ol>
</details>

1000
2020/solutions/9/data.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,50 @@
from os.path import join, dirname
from typing import List, Optional, Set, Tuple
from itertools import combinations
class XMAS:
def __init__(self, data: str, size: int) -> None:
self.size: int = size
self.position: int = size
self.buffer: List[int] = [
int(x)
for x in data.strip().split('\n')
]
def check_next(self) -> bool:
possible = [
a + b
for a, b in combinations(self.buffer[self.position - self.size: self.position], 2)
]
return self.buffer[self.position] in possible
def find_first_invalid(self) -> int:
l = len(self.buffer)
while self.position < l:
valid = self.check_next()
if not valid:
return self.buffer[self.position]
self.position += 1
raise Exception
def find_slice(self, target: int):
l = len(self.buffer)
for n in range(l):
for m in range(n, l):
slice = self.buffer[n: m]
if sum(slice) == target:
return min(slice) + max(slice)
raise Exception
data = join(dirname(__file__), '../data.txt')
with open(data) as f:
xmas = XMAS(f.read(), 25)
first_invalid = xmas.find_first_invalid()
print(first_invalid)
solution = xmas.find_slice(first_invalid)
print(solution)

20
2020/solutions/9/test.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