Added 2020 (python)

This commit is contained in:
Karma Riuk 2023-08-02 11:39:56 +02:00
commit 410815acf8
93 changed files with 11719 additions and 0 deletions

200
2020/1/input Normal file
View File

@ -0,0 +1,200 @@
1946
1859
1654
1806
1648
1873
1216
1831
1610
1779
1626
1332
1713
1919
1353
1720
1818
1976
1993
1617
1678
1655
1725
1686
1737
1696
1046
1814
1909
1618
2006
1903
1528
1635
1457
1924
1734
1723
1735
1984
1846
1921
1587
2009
1607
1987
1910
1571
1898
1869
1537
1446
1535
1802
1847
1966
1944
1793
1383
1850
1274
347
1208
1748
1906
1771
1849
1773
1792
1705
1538
1564
2003
1994
1545
1704
1657
1483
1701
1724
1293
1834
1712
1950
1844
1290
1692
1820
1585
1986
1328
1841
1709
1232
1945
1684
1787
1991
1914
16
1977
1620
1825
1866
1615
1832
496
1932
1819
1559
1870
1677
1650
1594
1664
1600
1622
1862
1937
1624
1580
1931
1803
1839
1755
1952
1473
1694
1864
1178
1163
1790
393
1776
1871
1999
1923
1174
1557
1646
1200
1842
1432
1573
1913
1954
1599
1980
1948
1430
1298
1835
1643
1742
1609
1649
1382
1343
1263
1908
1703
1922
1764
1603
1330
588
954
1772
1553
975
1499
1552
1214
1829
1698
1797
1807
1961
1947
1845
1881
1821
1815
1623
1675
1478
1886
1951
1700
1890
1876
1781
1853
1983
1901
1939
1292
853
1879
1652

75
2020/1/prog.py Normal file
View File

@ -0,0 +1,75 @@
def get_file_input(filename):
ret = set()
with open("input", "r") as f:
for i, line in enumerate(f.readlines()):
if " " in line:
raise ValueError(f"Only on value can be put per line in the input file (space detected at line {i} the input file).")
ret.add(int(line))
return ret
def get_2_numbers(s: set):
goal = 2020
known = set()
for e in s:
sub_goal = 2020 - e
if sub_goal in known:
return e, sub_goal
known.add(e)
def init_dict(s: set):
ret = dict()
for e in s:
ret[e] = {e}
return ret
def get_n_numbers(n_entries: int, s: set, data: dict):
if data == {}:
data = init_dict(s)
if n_entries == 2:
goal = 2020
for e in s:
sub_goal = 2020 - e
if sub_goal in data.keys():
return e, *data[sub_goal]
else:
new_data = {}
for e in s:
for result, values in data.items():
if e in values: pass
new_data[result + e] = values | {e}
return get_n_numbers(n_entries - 1, s, new_data)
def get_result(*ns: int):
ret = 1
for n in ns:
ret *= n
return ret
def main(n_entries = 2, use_sample_input = True):
sample = { 1721,
979,
366,
299,
675,
1456}
res = get_result(
*get_n_numbers(
n_entries,
sample if use_sample_input else get_file_input("input"),
{})
)
if use_sample_input:
expected = 241861950 if n_entries == 3 else 514579 # if n_entries == 2
return f"{res} {res==expected}".upper()
else:
return res
print(main(n_entries = 3, use_sample_input = False))

Binary file not shown.

93
2020/10/input Normal file
View File

@ -0,0 +1,93 @@
47
99
115
65
10
55
19
73
80
100
71
110
64
135
49
3
1
98
132
2
38
118
66
116
104
87
79
114
40
37
44
97
4
140
60
86
56
133
7
146
85
111
134
53
121
77
117
21
12
81
145
129
107
93
22
48
11
54
92
78
67
20
138
125
57
96
26
147
124
34
74
143
13
28
126
50
29
70
39
63
41
91
32
84
144
27
139
33
88
72
23
103
16

23
2020/10/prog.py Normal file
View File

@ -0,0 +1,23 @@
def get_input(sample = False, number = 1):
with open(f"sample_{number}" if sample else "input", 'r') as f:
return [int(i) for i in f.readlines()]
def get_result(data: list, part = 1):
data.sort()
data = [0] + data + [data[-1] + 3]
diffs = []
for i in range(len(data) - 1):
n1, n2 = data[i], data[i + 1]
diffs.append(n2 - n1)
if part == 1:
return diffs.count(1) * diffs.count(3)
else:
for diff in diffs
return 0
if __name__ == "__main__":
print(get_result(get_input()))

11
2020/10/sample_1 Normal file
View File

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

31
2020/10/sample_2 Normal file
View File

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

12
2020/10/test.py Normal file
View File

@ -0,0 +1,12 @@
from prog import *
inp_1 = get_input(sample = True, number = 1)
result_1_1 = get_result(inp_1)
expected_1_1 = 35
print(f"{result_1_1 = } {result_1_1 == expected_1_1}")
inp_2 = get_input(sample = True, number = 2)
result_1_2 = get_result(inp_2)
expected_1_2 = 220
print(f"{result_1_2 = } {result_1_2 == expected_1_2}")

Binary file not shown.

91
2020/11/input Normal file
View File

@ -0,0 +1,91 @@
LLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLLLLLLLLL.LLLL..LLLLLLL..LLLLLL.LLLLLLLL.L.LLLLLLLLLLL
LLLLL.LL.LLLLLLL.LLLLL.LLLLL.LLLLLLL..LLLLLLLLLLLLLLLL.LLLLLLLLLL.LL.L.LLLLL.LLL.LLLL..LLLLLLLLLLL.
LLLLLLLL.LLLLLLLLL.LLL.LLLL..LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLL.LL.LLLL.LLLLL.L.LLL.LLLLLLLLLLL.LLLL.L
L.LLLLL..LLLLLLL..LLL.LLLLLL.LLLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLLLLL.LLLLLLLLLLLLL
LLLLLLLLLLLLLLL...LLLLLLLLL..L.LLLLLLLLLLLLLLLL.LLL.LL.LLLLL.LLLLLLLLLLLLLLL.LLLLLLLL.LLLLLL.LLLLLL
LLLLLLLL.LLLLLLL.LLLLL.LLLLL.LLLLLLLLL.LLLLLLLL.LLLLLLLLLLLL.LLLLLLL.LLLLLLLLLLLLLL.LLLLLLLL..LLLLL
LL.LLLLL.LLLLLLL.LLLLL.LLLLL.LLLLLLLLLL.LLLL.LL.LLLLLL.LLL.LLL.LLL.LLLLL.LLL.LLLLLLLL..L.LLLLLLLL.L
LLLLLLLL.LLLL.LLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLL..LLL.LL.LLLLLLL.LLLLLLLL..LLLLLLLLLLLL
LLLLLLLL.LLLLLLL.LLLLL.LLLLL.LL.LLLLL.LLLLLLLLL.LLLLLL.LLL.L.LLLLLLLLLLLLLLL.LL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L.LLLLLLLL.LLLLL.LLLLLLL
LLLLLLLL.LLLLLLL.LLLLL.LLLL..LLLLLLLL.LLLLLL.LL.L.LLLL.LLLLL.LLL.LLL.LLLLLLL.LLLLL.LLLLLLLLL.LLLLL.
LLLLLLLLLLLLLLLLLLLL.L.LLLLLLLLLLLLLL.LLLL.LLLL.LLLLLL.LLLLL..LLLLLL.LLLLLLL.LLLLL.LL.LLLLLL.LLLLLL
LLLLLLLL.LLLLLLLLLLLLL.LLLLL.LLLLLLLL.LLLLLLLLL.LLL.LL.L.LLLLLLLL.LLLLLLLLLL.LLLLLLLLLLLLLLLL.LLLLL
LLLLLLLL.LLLLLLL.LLLLL.LLLLLLLLLLLLLL.LLLL.LLLL.LLLLLL.LLLLL.LLLLLLL.LLLLLLLLLL.LLLLL.LLLLLL.LLLLLL
LLL.LLLLLLLLLLLL.LLLLL.LLL.LLLLLLLLLLLLLLLLLLLLLLL.LLL.LLLLL.LLLLLLL.LLLLLLL.LLLL.LLL.LLLLLL.LLLLLL

118
2020/11/prog.py Normal file
View File

@ -0,0 +1,118 @@
def get_input(sample = False, sample_name = "sample"):
with open(sample_name if sample else "input", "r") as f:
return [list(l.strip()) for l in f.readlines()]
def is_there_occupied(range_x, range_y, seats):
try:
for x, y in zip(range_x, range_y):
# print(f"\tChecking: {x}, {y}")
if seats[y][x] == "#":
# print(f"\tFound an # at {x}, {y}")
return True
elif seats[y][x] == "L":
return False
return False
except IndexError:
return False
def count_occupied_direction(center_x, center_y, seats):
count = 0
len_x = len(seats[0])
len_y = len(seats)
directions = [
( # N
[center_x] * center_y,
range(center_y - 1, -1, -1)
),
( # NE
range(center_x + 1, len_x),
range(center_y - 1, -1, -1)
),
( # E
range(center_x + 1, len_x),
[center_y] * (len_x - center_x)
),
( # SE
range(center_x + 1, len_x),
range(center_y + 1, len_y)
),
( # S
[center_x] * (len_y - center_y),
range(center_y + 1, len_y)
),
( # SW
range(center_x - 1, -1, -1),
range(center_y + 1, len_y)
),
( # W
range(center_x - 1, -1, -1),
[center_y] * center_x
),
( # NW
range(center_x - 1, -1, -1),
range(center_y - 1, -1, -1),
)
]
for range_x, range_y in directions:
if is_there_occupied(range_x, range_y, seats):
count += 1
return count
def count_occupied_around(center_x, center_y, seats):
count = 0
len_x = len(seats[0])
len_y = len(seats)
for y in range(center_y-1, center_y+2):
for x in range(center_x-1, center_x+2):
if x in range(len_x) and y in range(len_y) and (x, y) != (center_x, center_y):
if seats[y][x] == "#" : count += 1
return count
def get_dummy_seats(len_x, len_y):
ret = []
for y in range(len_y):
line = ""
for x in range(len_x):
line += "."
ret.append(line)
return ret
def get_result(seats: list, part = 1):
len_x = len(seats[0])
len_y = len(seats)
prev_seats = get_dummy_seats(len_x, len_y)
while prev_seats != seats:
new_seats = [[item for item in line] for line in seats]
for y in range(len_y):
for x in range(len_x):
place = seats[y][x]
if place == ".": continue
count = count_occupied_around(x, y, seats) if part == 1 else count_occupied_direction(x, y, seats)
if place == "L" and count == 0:
new_seats[y][x] = "#"
elif place == "#" and count >= (4 if part == 1 else 5):
new_seats[y][x] = "L"
prev_seats = seats
seats = new_seats
count = 0
for line in seats:
for char in line:
if char == "#": count += 1
return count
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

10
2020/11/sample Normal file
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,7 @@
.##.##.
#.#.#.#
##...##
...L...
##...##
#.#.#.#
.##.##.

16
2020/11/test.py Normal file
View File

@ -0,0 +1,16 @@
from prog import *
inp = get_input(sample = True)
result_1 = get_result(inp)
expected_1 = 37
print(f"{result_1 = } {result_1 == expected_1}")
print()
inp_no_occupied = get_input(sample = True, sample_name = "sample_no_occupied")
print(count_occupied_direction(3, 3, inp_no_occupied))
result_2 = get_result(inp, part = 2)
expected_2 = 26
print(f"{result_2 = } {result_2 == expected_2}")

Binary file not shown.

Binary file not shown.

760
2020/12/input Normal file
View File

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

67
2020/12/prog.py Normal file
View File

@ -0,0 +1,67 @@
def get_input(sample = False):
with open("sample" if sample else "input") as f:
return [(line[:1], int(line[1:])) for line in f.readlines()]
def new_dir_after_rotate(cur_dir: str, L_or_R: str, amount: int):
orientations = ["N", "E", "S", "W"]
cur_dir_i = orientations.index(cur_dir)
return orientations[(cur_dir_i + (1 if L_or_R == "R" else -1) * amount // 90) % len(orientations)]
def new_waypoint_after_rotate(cur_wp: list, L_or_R: str, amount: int):
ret = [0, 0]
rot = amount // 90 % 4
if (rot, L_or_R) == (1, "L") or (rot, L_or_R) == (3, "R"):
ret[0] = -cur_wp[1]
ret[1] = cur_wp[0]
elif rot == 2:
ret[0] = -cur_wp[0]
ret[1] = -cur_wp[1]
elif (rot, L_or_R) == (3, "L") or (rot, L_or_R) == (1, "R"):
ret[0] = cur_wp[1]
ret[1] = -cur_wp[0]
return ret
def get_result(instructions: dict, part = 1):
position = [0, 0]
waypoint = [10, 1]
cur_dir = "E"
add_to_vertical = lambda dir, x: (1 if dir == "N" else -1) * x
add_to_horizontal = lambda dir, x: (1 if dir == "E" else -1) * x
for cmd, amount in instructions:
if part == 1:
if cmd == "F":
if cur_dir in ["N", "S"]:
position[1] += add_to_vertical(cur_dir, amount)
elif cur_dir in ["E", "W"]:
position[0] += add_to_horizontal(cur_dir, amount)
elif cmd in ["L", "R"]:
cur_dir = new_dir_after_rotate(cur_dir, cmd, amount)
elif cmd in ["N", "E", "S", "W"]:
if cmd in ["N", "S"]:
position[1] += add_to_vertical(cmd, amount)
elif cmd in ["E", "W"]:
position[0] += add_to_horizontal(cmd, amount)
else:
if cmd == "F":
position[0] += waypoint[0] * amount
position[1] += waypoint[1] * amount
elif cmd in ["L", "R"]:
waypoint = new_waypoint_after_rotate(waypoint, cmd, amount)
elif cmd in ["N", "E", "S", "W"]:
if cmd in ["N", "S"]:
waypoint[1] += add_to_vertical(cmd, amount)
elif cmd in ["E", "W"]:
waypoint[0] += add_to_horizontal(cmd, amount)
return sum(map(lambda x: abs(x), position))
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

5
2020/12/sample Normal file
View File

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

64
2020/12/test.py Normal file
View File

@ -0,0 +1,64 @@
import unittest
from prog import *
class Rotate(unittest.TestCase):
def test_rotate_L90(self):
self.assertEqual(new_dir_after_rotate("N", "L", 90), "W")
self.assertEqual(new_dir_after_rotate("E", "L", 90), "N")
self.assertEqual(new_dir_after_rotate("S", "L", 90), "E")
self.assertEqual(new_dir_after_rotate("W", "L", 90), "S")
def test_rotate_R90(self):
self.assertEqual(new_dir_after_rotate("N", "R", 90), "E")
self.assertEqual(new_dir_after_rotate("E", "R", 90), "S")
self.assertEqual(new_dir_after_rotate("S", "R", 90), "W")
self.assertEqual(new_dir_after_rotate("W", "R", 90), "N")
def test_rotate_L180(self):
self.assertEqual(new_dir_after_rotate("N", "L", 180), "S")
self.assertEqual(new_dir_after_rotate("E", "L", 180), "W")
self.assertEqual(new_dir_after_rotate("S", "L", 180), "N")
self.assertEqual(new_dir_after_rotate("W", "L", 180), "E")
def test_rotate_R180(self):
self.assertEqual(new_dir_after_rotate("N", "R", 180), "S")
self.assertEqual(new_dir_after_rotate("E", "R", 180), "W")
self.assertEqual(new_dir_after_rotate("S", "R", 180), "N")
self.assertEqual(new_dir_after_rotate("W", "R", 180), "E")
def test_rotate_L270(self):
self.assertEqual(new_dir_after_rotate("N", "L", 270), "E")
self.assertEqual(new_dir_after_rotate("E", "L", 270), "S")
self.assertEqual(new_dir_after_rotate("S", "L", 270), "W")
self.assertEqual(new_dir_after_rotate("W", "L", 270), "N")
def test_rotate_R270(self):
self.assertEqual(new_dir_after_rotate("N", "R", 270), "W")
self.assertEqual(new_dir_after_rotate("E", "R", 270), "N")
self.assertEqual(new_dir_after_rotate("S", "R", 270), "E")
self.assertEqual(new_dir_after_rotate("W", "R", 270), "S")
def test_rotate_L360(self):
self.assertEqual(new_dir_after_rotate("N", "L", 360), "N")
self.assertEqual(new_dir_after_rotate("E", "L", 360), "E")
self.assertEqual(new_dir_after_rotate("S", "L", 360), "S")
self.assertEqual(new_dir_after_rotate("W", "L", 360), "W")
def test_rotate_R360(self):
self.assertEqual(new_dir_after_rotate("N", "R", 360), "N")
self.assertEqual(new_dir_after_rotate("E", "R", 360), "E")
self.assertEqual(new_dir_after_rotate("S", "R", 360), "S")
self.assertEqual(new_dir_after_rotate("W", "R", 360), "W")
class Result(unittest.TestCase):
def setUp(self):
self.inp = get_input(sample = True)
def test_part_1(self):
result = get_result(self.inp)
self.assertEqual(result, 25)
def test_part_2(self):
result = get_result(self.inp, part = 2)
self.assertEqual(result, 286)

Binary file not shown.

Binary file not shown.

2
2020/13/input Normal file
View File

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

52
2020/13/prog.py Normal file
View File

@ -0,0 +1,52 @@
from math import gcd
def get_input(sample = False):
with open("sample" if sample else 'input', 'r') as f:
ret = []
lines = f.readlines()
ret.append(int(lines[0]))
ret.append([int(x) if x != "x" else x for x in lines[1].split(',')])
return ret
def get_next_bus_departure(bus_id: int, cur_time: int):
return bus_id * math.ceil(cur_time / bus_id)
def get_result(data: list, part = 1):
cur_time = data[0]
busses = data[1]
if part == 1:
eta_n_bus = {}
for bus in busses:
if bus == 'x': continue
eta = get_next_bus_departure(bus, cur_time)
eta_n_bus[eta] = bus
earliest = min(eta_n_bus.keys())
earliest_bus = eta_n_bus[earliest]
waiting_time = earliest - cur_time
return waiting_time * earliest_bus
else:
step = busses[0]
bus_n_offsets = [(bus, offset) for offset, bus in enumerate(busses) if bus != 'x']
time = 0
for bus, offset in bus_n_offsets[1:]:
while True:
time += step
if (time + offset) % bus == 0:
step = lcm(step, bus)
break
return time
def lcm(a, b):
return abs(a*b) // gcd(a, b)
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

2
2020/13/sample Normal file
View File

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

20
2020/13/test.py Normal file
View File

@ -0,0 +1,20 @@
from prog import *
import unittest
class Methods(unittest.TestCase):
def test_get_input(self):
inp = get_input(sample = True)
self.assertEqual(inp, [939, [7, 13, 'x', 'x', 59, 'x', 31, 19]])
class Result(unittest.TestCase):
def setUp(self):
self.inp = get_input(sample = True)
def test_part_1(self):
self.assertEqual(get_result(self.inp), 295)
def test_part_2(self):
self.assertEqual(get_result([0, [7, 13]], part = 2), 77)
self.assertEqual(get_result([0, [17, 'x', 13, 19]], part = 2), 3417)
self.assertEqual(get_result(self.inp, part = 2), 1068781)

Binary file not shown.

Binary file not shown.

554
2020/14/input Normal file
View File

@ -0,0 +1,554 @@
mask = 1110X1110XXX101X0011010X110X10X0110X
mem[40257] = 51331021
mem[18433] = 464024066
mem[9993] = 463909
mask = 11X011010X110X101X011X1X010X10100001
mem[54152] = 692939
mem[31079] = 22525259
mem[33597] = 474240
mem[3881] = 919507
mem[24651] = 48975360
mem[14815] = 1554
mem[17731] = 1337580
mask = X0X0111111000000100101100X000X10X001
mem[56856] = 474071
mem[3724] = 29660
mem[18229] = 189
mem[34570] = 419796001
mem[11355] = 65374715
mem[37999] = 522634
mask = 1111X0111XX00000111X1010X1101XX01110
mem[3262] = 99770791
mem[4906] = 11370
mem[12532] = 1083912
mask = 10110101101X1X00X1111010001001010X10
mem[46252] = 84993342
mem[5286] = 1013690
mask = 11X001110111101X001101XX100110001010
mem[55055] = 516
mem[38350] = 615
mem[51960] = 2038
mem[61990] = 957107
mem[24357] = 8172
mask = 1XXX1111X101001X011X000X110110001X01
mem[57990] = 3734
mem[50349] = 101222011
mem[45511] = 42986512
mem[40272] = 403
mem[54329] = 1626458
mem[26816] = 448210757
mask = 11101111011000X01X1XX100X0XXX010X001
mem[51488] = 333041
mem[30893] = 3258
mem[31999] = 14972408
mem[48851] = 74906
mem[22619] = 3442368
mask = 0X000X11X10XXX101011010X001111111011
mem[6850] = 1224301
mem[48485] = 34534000
mem[24614] = 1055775
mask = 0100X11101X100X0X11100XX110011101100
mem[18755] = 100409700
mem[31397] = 114132362
mask = 1110111111000X011XX1X10011X001011001
mem[25234] = 575
mem[54990] = 110437
mem[5738] = 872
mem[37430] = 206977297
mem[40257] = 767384
mem[478] = 5752
mask = 111001110111101X001101X1100110X010X1
mem[21231] = 2835725
mem[14092] = 1259011
mem[23506] = 3099
mask = 1110001X1111001X1101101XXX100X0010XX
mem[37900] = 79419475
mem[37628] = 125826
mem[11380] = 624
mem[36032] = 284016390
mem[47266] = 767
mask = XX10X1101101XXX0111110011100X111110X
mem[48427] = 18603
mem[19559] = 124107997
mem[49782] = 29154
mem[3724] = 136805
mem[49580] = 148450462
mem[54342] = 180288875
mask = 110011110101X01001X10XX11X1XX111X011
mem[49856] = 445359
mem[7226] = 4303932
mem[62181] = 12485531
mem[45386] = 1037
mask = X1X01111X1010010XX11X1000100XX1000X1
mem[32337] = 31771
mem[55567] = 1438485
mem[49504] = 452407
mem[15890] = 64458173
mem[9930] = 43490551
mask = 101X1111111X00101X110X100100XX111101
mem[11172] = 30476781
mem[16705] = 10356
mem[9799] = 3517752
mem[35121] = 991958953
mem[12861] = 13640943
mem[15424] = 98158
mask = X110011X010XX01100X100010X1XX0001101
mem[31621] = 456005334
mem[57990] = 5145
mem[7067] = 127283
mem[57106] = 322139
mem[49968] = 2140844
mask = 1X1001X1X01X10110XX101XX010X00000100
mem[42602] = 128159
mem[26816] = 7253653
mem[26531] = 42978
mem[7592] = 249896576
mem[7956] = 1315
mask = 111011X1X11100X011X1010101XXX0XX0010
mem[52446] = 1677086
mem[44919] = 1499581
mem[34842] = 5043767
mem[24471] = 579304892
mem[4380] = 1934
mem[44081] = 2818
mask = X1101X0X110X00X111X001001100111X0010
mem[44457] = 10924
mem[61114] = 41913513
mem[25625] = 1074
mem[53821] = 4293765
mem[21864] = 895125
mem[18764] = 24202
mask = X111011X0110XX0X1011110111000011000X
mem[28782] = 3396
mem[51935] = 250016
mem[29096] = 1633
mask = 100011111X0X000X1011101X00001100X011
mem[50213] = 21062
mem[17583] = 17889
mem[6214] = 755665
mem[41630] = 554432
mem[36640] = 21683065
mem[9993] = 663
mask = 10X0111111X00010X0X1000X0000101X1000
mem[31206] = 1563
mem[31999] = 893563867
mem[25234] = 16239
mem[16826] = 1185
mem[6325] = 308015
mask = 111000X11101001X11X1010000101XXX0010
mem[714] = 174841
mem[47336] = 1080
mem[48590] = 5902057
mask = 111011110X1100001101101111X10101X1X1
mem[11741] = 285199
mem[32864] = 794118
mem[50294] = 3086
mem[21244] = 13500488
mem[52937] = 668328
mem[25942] = 14773413
mask = X11001111X10000011X101X0111010000X01
mem[55993] = 227666987
mem[54990] = 29299
mem[10848] = 14517154
mem[26412] = 920115307
mask = 1X0X11111100001XX00100X01X0010111101
mem[14992] = 62272953
mem[48256] = 5676
mem[19361] = 168138195
mem[144] = 986
mem[36032] = 911
mask = 1X10001111110X1X110X10X1X01X1010X001
mem[9960] = 4200
mem[8832] = 1841117
mask = 111X111101X00X101X11010000111111X001
mem[32864] = 15880
mem[9966] = 7278514
mem[46710] = 1818748
mem[1863] = 13021558
mask = 1110001111X1001011X11001101000XX0XXX
mem[63705] = 3162416
mem[45211] = 686629227
mem[26397] = 17094
mem[9999] = 783527
mem[25355] = 2865745
mem[37999] = 982
mask = XXX01111110000XX10X10100010XX1X01001
mem[36032] = 1405160
mem[25234] = 10488275
mem[56856] = 9235
mem[62886] = 10583974
mask = 01000111X10X00X11011X0X11010111XX00X
mem[9960] = 108631252
mem[20641] = 236021
mem[54181] = 898590
mem[47206] = 357135433
mask = 0X00X11111010010111X0000011001110X01
mem[34160] = 168879
mem[31424] = 28869180
mem[24916] = 10670389
mem[738] = 352
mem[47762] = 8844766
mask = 111011X10110X010X011X00000001100XXXX
mem[22643] = 52619618
mem[26725] = 18104217
mem[51488] = 348349
mask = 1X1011110XXX00101111100000110000X10X
mem[56604] = 38442
mem[64943] = 178378
mem[14699] = 13770627
mask = 11X01111001010X01011100000010X10X010
mem[17095] = 9031632
mem[21925] = 157279
mem[16803] = 28186944
mask = 010XX11XX1X0001X10X11101X00111011X01
mem[18863] = 1188008
mem[5968] = 795
mem[43052] = 2990150
mem[38515] = 747
mem[44368] = 496
mem[45434] = 2077409
mask = 0X10111X111100111X1X000XXX00X01X1010
mem[13059] = 23890054
mem[51572] = 29407
mem[39964] = 4094674
mem[59053] = 5346433
mask = 1110011111X100X011011X11111110X11100
mem[1791] = 12339300
mem[51641] = 105572
mem[22529] = 1649
mem[29570] = 930208
mask = 11101111X1XX00101X111000XX000X10X0X1
mem[19744] = 1667
mem[18167] = 556
mem[52216] = 39333
mem[8118] = 28457779
mem[14409] = 7493808
mem[32337] = 34018
mask = 0110X1111X010X10001X1110011X0010001X
mem[40] = 27424
mem[6244] = 41469
mem[6612] = 214
mem[36981] = 34852720
mem[35860] = 74811624
mem[44120] = 82357013
mem[5999] = 395
mask = X1X0111111000001XX11X1000XX001000010
mem[12392] = 8235335
mem[52538] = 236135318
mem[7227] = 6809
mask = 111011X10110X010111100001X00X00000X1
mem[13662] = 270146
mem[49569] = 11401458
mem[49782] = 12256
mask = X11X11110X10X000101111XXXX0100100001
mem[63774] = 25139
mem[47309] = 107486126
mem[39140] = 884
mem[35267] = 2032
mem[16513] = 3724990
mem[47901] = 120378235
mem[47121] = 574
mask = 1100X1X100110110XX010111110111101111
mem[21716] = 53071834
mem[9997] = 343
mem[34175] = 109609
mem[22643] = 59660540
mask = 011X1X10111X001111X100X1011010100001
mem[2872] = 4637
mem[7429] = 13346151
mem[21514] = 521995
mask = 0111X1X1X11010001011X10011000X11110X
mem[34817] = 34195656
mem[59139] = 1538904
mem[33597] = 7322219
mem[43471] = 2053
mem[31759] = 352
mem[24649] = 393907
mask = 0010X1111X10001010X100001X010011111X
mem[53821] = 389983024
mem[30685] = 681448
mem[14409] = 8810596
mem[58403] = 202202
mem[59589] = 11132409
mem[36376] = 1035668
mem[10107] = 282
mask = 1X00110101X1001010011010X0100000X001
mem[35009] = 1137976
mem[30376] = 893048407
mem[44428] = 1634
mask = X01X11111111001X111X10X111X00X1111X0
mem[3088] = 1335
mem[57928] = 2122936
mem[14992] = 1850
mem[50886] = 596
mem[20951] = 1834738
mask = X11111X1X0X000001X11XX1010X10X000001
mem[46309] = 1344734
mem[57393] = 7607663
mem[64140] = 412481329
mem[31937] = 4156010
mask = 01000XX11100XX1110X10X00X011X11010X0
mem[21092] = 188978
mem[58601] = 747
mask = 11101XX11100X001100001000X0000X11X10
mem[49580] = 681666
mem[28396] = 6693
mem[21446] = 2871
mem[8409] = 129741145
mem[26851] = 64088468
mask = 1X101111X111X001101010X001000000XX11
mem[50617] = 2893221
mem[44352] = 351080
mem[6973] = 74704635
mem[35215] = 58274979
mem[34986] = 204485850
mem[46431] = 483390728
mask = 11101X11011100101101X00X010010X0X100
mem[21875] = 106030145
mem[18755] = 2197864
mem[21518] = 110524
mask = 101001011101X0001111XX01X000010X10X1
mem[3866] = 10698
mem[25215] = 23678
mem[16705] = 8210939
mem[40472] = 1601
mem[43847] = 4262784
mem[20280] = 845863570
mask = X110XX1XX101001011X101X01000X00100X1
mem[57100] = 7125772
mem[64179] = 73893
mem[54526] = 3175087
mem[62001] = 1973479
mask = 11X0111XXX00001010111X00X00X0XX01011
mem[54845] = 10595
mem[31178] = 10986515
mem[16074] = 765117
mem[39388] = 548
mem[16713] = 2599663
mask = 0100X111110100XX1X11X1X1001000110XX1
mem[21508] = 3155
mem[28193] = 144849
mem[8918] = 5192
mem[610] = 1144170
mem[61348] = 102390786
mem[43515] = 27343
mem[63705] = 10436512
mask = X100X11101000011101XXXX1101001XX0X01
mem[47313] = 28073
mem[33901] = 90318443
mem[64222] = 7293
mask = X110111XX11X00011X1X101X0100000XX001
mem[24490] = 2682
mem[9264] = 627919
mem[1411] = 8120967
mem[17130] = 1272496
mem[2438] = 30859917
mask = 110XXX111101X0X00X11100X010X011001X1
mem[6973] = 19850171
mem[51470] = 67939742
mask = 10100111110100XX111100XX1X01X0010110
mem[11147] = 30
mem[22117] = 3508
mem[32551] = 29083435
mask = 101001XX1101X0001111X0010X01XXX11X01
mem[18544] = 482715873
mem[56829] = 24246491
mem[19107] = 39530
mem[11939] = 361324
mem[64069] = 3257668
mem[37976] = 2801177
mask = X1101101X1110X10X001101X10X0110001X1
mem[41961] = 94719
mem[5528] = 319045708
mem[31759] = 597770
mem[3298] = 54756
mem[39780] = 454394346
mask = 11101111X1X1X010111101001X101011XX0X
mem[6325] = 54296774
mem[53884] = 2248
mem[41087] = 315232205
mem[17418] = 227971462
mem[46081] = 5766
mask = 1010XX00X1011000X1110X0X000110XX1100
mem[36022] = 2440
mem[309] = 11100855
mem[40840] = 113562551
mem[51488] = 1410
mem[38724] = 80445305
mem[46414] = 693
mask = 100011111X010011X11100X01001XX0X1001
mem[6850] = 1658
mem[27296] = 2089
mem[34000] = 227145532
mem[36309] = 6512
mem[8049] = 41857993
mem[3603] = 2183079
mem[9019] = 583919731
mask = 11XX1XX1110000011X0XX1101100X101101X
mem[42218] = 3195265
mem[24649] = 20411584
mask = 1110111X0101X0100011000011000X00X001
mem[21925] = 945752010
mem[26816] = 463236906
mem[8118] = 75
mem[7382] = 3470
mem[24647] = 65907
mem[34226] = 703
mask = X11011111101X01011111011XX0000101001
mem[54526] = 523463
mem[12392] = 240399435
mask = X01011111110001011111XX00XX00011X001
mem[29635] = 370994023
mem[1064] = 1593105
mem[39783] = 4929783
mem[7721] = 3697
mem[19747] = 911509249
mem[12181] = 8022
mem[9277] = 269282378
mask = 1100111XXX0X000110X1X0001100010010X1
mem[62185] = 768934
mem[8118] = 238
mem[16448] = 67217
mem[1286] = 2768751
mask = 11X001X11110X0001111X01010X0X0000XX0
mem[26659] = 4857903
mem[15890] = 41829451
mem[61153] = 1745
mem[33685] = 1322893
mem[58844] = 22060038
mask = 11X0X111011100X011011111XXX00011001X
mem[41057] = 504
mem[9775] = 90755012
mem[35694] = 1327
mem[14023] = 5965
mem[46660] = 15962
mem[45618] = 93484
mask = X01111111X11001011100X01X000X0XXX01X
mem[41817] = 30341471
mem[40062] = 2045
mem[20631] = 3206
mem[57953] = 99
mask = X11011X101X11000111100011101X0001110
mem[53840] = 154298805
mem[46322] = 653989
mem[36288] = 427196
mem[50550] = 54235668
mem[61463] = 9653
mem[58758] = 8531442
mem[25942] = 187891326
mask = 1X1011111100001010X1X00000000X1XX001
mem[24145] = 670
mem[39140] = 8027405
mask = 01X01110X11000111111100X001100101X1X
mem[1858] = 465546026
mem[53156] = 33616871
mem[34303] = 3814644
mem[9993] = 424038168
mem[18379] = 105249
mask = 1110111X0111001X111101010X11X00X1010
mem[37628] = 1729777
mem[14716] = 37020621
mem[40472] = 633
mask = 1110111XX11X000X1111001X01000011X00X
mem[32816] = 22945
mem[58409] = 4261203
mask = 0110111111110001110X0X1XX111X01110X1
mem[25234] = 1845
mem[11313] = 26080
mem[9420] = 894744
mem[55530] = 854
mask = 011011101X11001111X100X00011X0010100
mem[11839] = 96131
mem[53757] = 1408
mem[44034] = 27236
mem[2385] = 383509
mask = 111111110XX000001X110X0X00010000XX1X
mem[32942] = 18689
mem[45731] = 632528
mem[51515] = 65228710
mem[7190] = 512188
mem[55271] = 109657287
mask = X1101X1111110000111X0X0001001110X010
mem[31454] = 53024958
mem[39884] = 1067
mem[45511] = 12320135
mem[49866] = 122369
mem[57038] = 27967196
mem[29561] = 2925457
mask = 1X1XXXX11X10X0001111101101101000011X
mem[5666] = 246869
mem[16826] = 4819818
mem[9708] = 56613002
mem[19527] = 979537
mem[46710] = 1863
mem[24930] = 9732123
mask = 0010X11111XX00101X110X0011100X01X000
mem[54809] = 7602
mem[46221] = 1952
mem[18345] = 3892597
mem[5738] = 9611
mem[53884] = 2050573
mem[35694] = 1819
mem[52446] = 1143
mask = 01001111110100XX0XXX010000001010XX01
mem[7226] = 7110
mem[58560] = 9302
mem[47854] = 13408926
mem[50530] = 115326557
mask = 00101111111000101111000X010X001X00X0
mem[46080] = 88122926
mem[36726] = 990065
mem[6612] = 244727289
mem[3724] = 7537840
mem[41817] = 244009305
mem[42763] = 100935344
mask = 11111X110010X0001X1111000X1000111101
mem[29093] = 3116673
mem[17213] = 576
mem[42218] = 742524
mask = 00101X101X010010111X11X1110001X10X1X
mem[18167] = 5096
mem[18013] = 110009
mem[12532] = 548
mem[58899] = 72440595
mask = 00111111X111X0111110X1011X1101111001
mem[12181] = 417885
mem[28523] = 561
mem[63924] = 785190
mem[31937] = 27019144
mem[569] = 149095763
mem[54809] = 2678
mem[14355] = 15451
mask = 10101X11X1000X1X100111011001X1101001
mem[29525] = 27635
mem[38648] = 286224
mem[40257] = 33000302
mem[2385] = 87334
mask = 100011X1110000X1X0010X10X10001011011
mem[10671] = 752653692
mem[29096] = 28346
mem[64943] = 5823968
mem[8985] = 1725
mem[14409] = 432068
mask = 11101X11XX11X00011110X0111X11X001X10
mem[35782] = 26162
mem[18167] = 265539
mem[53514] = 17777350
mask = 0110111X111X00X111X100000111X0100XXX
mem[11289] = 25199
mem[21966] = 1577738
mem[33100] = 7214029
mem[14371] = 225814
mask = 1110X111111000X011X11X1XX0XX0010X000
mem[54809] = 164605380
mem[38947] = 1624427
mem[63150] = 221584
mask = 11101111XX0110X0X01101X010XX101X1X00
mem[28523] = 622707
mem[8072] = 227741
mem[6611] = 15393
mem[2600] = 386986740
mask = 110010X111010X10X1110001X11001110101
mem[46256] = 1543619
mem[58524] = 128793487
mem[39996] = 2787

69
2020/14/prog.py Normal file
View File

@ -0,0 +1,69 @@
import re
def get_input(sample = False, sample_n = 1):
with open(f"sample_{sample_n}" if sample else 'input', 'r') as f:
return [line.strip() for line in f.readlines()]
def parse_val_masks(mask: str):
mask_0 = 0
mask_1 = 0
for c in mask:
if c == "X":
mask_0 = (mask_0 << 1) + 1
mask_1 = mask_1 << 1
elif c == "0":
mask_0 = mask_0 << 1
mask_1 = mask_1 << 1
elif c == "1":
mask_0 = (mask_0 << 1) + 1
mask_1 = (mask_1 << 1) + 1
return mask_0, mask_1
def masked_value(value: int, masks: tuple):
return (value & masks[0]) | masks[1]
def decode_memory_address(address: int, mask: str):
ret = {address}
for i, c in enumerate(mask):
shift_amount = len(mask) - 1 - i
if c in ['1', 'X']:
new_ret = set()
for addr in ret:
if c == '1':
new_ret.add(addr | (1 << shift_amount))
elif c == 'X':
new_ret.update((addr | (1 << shift_amount), addr & ~(1 << shift_amount)))
ret = new_ret
return ret
def get_result(instructions: list, part = 1):
mem_re = re.compile(r'^mem\[(\d+)\] = (\d+)$')
mask_re = re.compile(r'^mask = ([X10]{36})$')
mem = {}
val_masks = (0, 0)
mem_masks = ""
for cmd in instructions:
if match := mem_re.match(cmd):
index, value = (int(x) for x in match.groups())
indexes = {index} if part == 1 else decode_memory_address(index, mem_mask)
for i in indexes:
mem[i] = masked_value(value, val_masks) if part == 1 else value
elif match := mask_re.match(cmd):
val_masks = parse_val_masks(*match.groups())
mem_mask = match.groups()[0]
else:
raise ValueError(f"The instruction `{cmd}` is not valid")
return sum(mem.values())
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

4
2020/14/sample_1 Normal file
View File

@ -0,0 +1,4 @@
mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
mem[8] = 11
mem[7] = 101
mem[8] = 0

4
2020/14/sample_2 Normal file
View File

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

42
2020/14/test.py Normal file
View File

@ -0,0 +1,42 @@
from prog import *
import unittest
class Methods(unittest.TestCase):
def test_parse_masks(self):
self.assertEqual(
parse_masks("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X"),
(
0b111111111111111111111111111111111101,
0b000000000000000000000000000001000000
)
)
self.assertEqual(
parse_masks("XXXXXXXXX1XXXXXXXX1X0XXXXXXXX1XXXX0X"),
(
0b111111111111111111110111111111111101,
0b000000000100000000100000000001000000
)
)
self.assertEqual(
parse_masks("XXXXX11XXXX1XX000XX0XXXXXXXXX1XXXX0X"),
(
0b111111111111110001101111111111111101,
0b000001100001000000000000000001000000
)
)
def test_decode_memory(self):
mask = "000000000000000000000000000000X1001X"
self.assertEqual(decode_memory_address(42, mask), {26, 27, 58, 59})
mask = "00000000000000000000000000000000X0XX"
self.assertEqual(decode_memory_address(26, mask), {16, 17, 18, 19, 24, 25, 26, 27})
class Result(unittest.TestCase):
def test_part1(self):
self.assertEqual(get_result(get_input(sample = True, sample_n = 1)), 165)
def test_part2(self):
self.assertEqual(get_result(get_input(sample = True, sample_n = 2), part = 2), 208)

Binary file not shown.

Binary file not shown.

14
2020/15/prog.py Normal file
View File

@ -0,0 +1,14 @@
from yaml import dump
def get_result(inp: list, part = 1):
last_pos = {n: i+1 for i, n in enumerate(inp[:-1])}
prev_item = inp[-1]
for i in range(len(inp), 2020 if part == 1 else 30_000_000):
cur_item = 0 if prev_item not in last_pos.keys() else i - last_pos[prev_item]
last_pos[prev_item] = i
prev_item = cur_item
return cur_item
if __name__ == "__main__":
print(get_result([20, 9, 11, 0, 1, 2], part = 2))

31
2020/15/test.py Normal file
View File

@ -0,0 +1,31 @@
from prog import *
import unittest
class Methods(unittest.TestCase):
pass
class Result(unittest.TestCase):
def test_p1(self):
self.assertEqual(get_result([0, 3, 6]), 436)
self.assertEqual(get_result([1, 3, 2]), 1)
self.assertEqual(get_result([2, 1, 3]), 10)
self.assertEqual(get_result([1, 2, 3]), 27)
self.assertEqual(get_result([2, 3, 1]), 78)
self.assertEqual(get_result([3, 2, 1]), 438)
self.assertEqual(get_result([3, 1, 2]), 1836)
def test_p2_1(self):
self.assertEqual(get_result([0, 3, 6], part = 2), 175594)
def test_p2_2(self):
self.assertEqual(get_result([1, 3, 2], part = 2), 2578)
def test_p2_3(self):
self.assertEqual(get_result([2, 1, 3], part = 2), 3544142)
def test_p2_4(self):
self.assertEqual(get_result([1, 2, 3], part = 2), 261214)
def test_p2_5(self):
self.assertEqual(get_result([2, 3, 1], part = 2), 6895259)
def test_p2_6(self):
self.assertEqual(get_result([3, 2, 1], part = 2), 18)
def test_p2_7(self):
self.assertEqual(get_result([3, 1, 2], part = 2), 362)

Binary file not shown.

Binary file not shown.

266
2020/16/input Normal file
View File

@ -0,0 +1,266 @@
departure location: 31-221 or 241-952
departure station: 27-780 or 787-957
departure platform: 34-405 or 411-970
departure track: 41-672 or 689-963
departure date: 26-827 or 843-970
departure time: 38-283 or 297-963
arrival location: 50-250 or 259-970
arrival station: 35-878 or 884-950
arrival platform: 49-746 or 772-955
arrival track: 37-457 or 481-954
class: 28-418 or 443-970
duration: 32-722 or 728-970
price: 41-519 or 525-966
route: 50-606 or 628-974
row: 46-92 or 111-967
seat: 41-112 or 135-972
train: 25-540 or 556-957
type: 39-574 or 585-954
wagon: 32-699 or 719-957
zone: 49-71 or 83-951
your ticket:
61,151,137,191,59,163,89,83,71,179,67,149,197,167,181,173,53,139,193,157
nearby tickets:
854,509,243,913,926,411,308,322,69,875,779,371,51,514,367,873,524,645,934,322
358,885,814,800,197,363,388,50,138,820,854,793,89,738,733,306,796,334,387,8
194,897,151,634,178,597,173,791,251,344,306,568,804,145,142,136,573,173,242,508
793,667,856,328,284,596,215,70,873,507,777,948,851,922,694,153,743,250,926,142
219,870,66,945,803,485,325,670,788,186,822,365,451,512,906,443,678,404,312,173
329,572,654,409,804,563,847,330,265,148,875,904,173,411,927,259,945,536,148,920
788,867,405,249,51,454,819,512,306,850,384,337,71,587,316,649,724,389,645,318
271,143,266,447,322,187,650,254,497,155,860,405,655,946,635,862,517,937,729,721
211,856,566,262,156,201,804,735,172,809,870,56,313,801,447,508,622,517,91,807
312,334,928,657,776,276,319,893,163,162,244,206,446,719,568,856,391,831,722,931
250,68,900,183,785,790,270,922,312,914,269,664,305,337,350,904,778,896,68,371
516,650,391,333,604,730,406,779,341,354,447,162,884,53,803,327,861,721,321,328
654,169,947,825,395,4,374,569,518,885,315,563,67,900,195,511,789,739,345,863
909,871,876,874,194,141,151,54,805,381,943,413,556,553,268,305,629,774,179,540
325,299,721,195,772,376,255,699,737,911,567,274,859,186,780,605,556,568,220,162
482,799,304,784,495,136,949,938,140,58,773,152,855,342,884,393,276,445,557,821
534,807,455,221,832,89,658,734,947,945,672,259,456,137,558,557,902,744,382,315
274,775,797,928,940,299,821,653,216,918,163,814,162,63,929,640,321,456,362,257
889,188,454,309,488,457,775,183,166,382,916,262,322,307,716,204,664,411,790,354
366,894,820,567,180,641,146,859,517,497,735,186,310,362,203,381,824,885,718,513
60,813,630,672,88,947,663,405,515,376,51,182,910,380,903,847,318,843,542,572
447,300,897,602,55,918,664,272,623,245,368,411,699,157,735,587,722,641,574,356
890,804,648,369,731,848,394,866,249,884,3,652,212,876,742,892,517,844,667,932
89,524,529,628,324,944,860,449,887,392,112,805,592,181,905,929,323,787,140,54
301,885,646,353,657,820,572,629,666,891,195,378,274,849,729,24,196,875,515,212
709,197,454,827,733,742,91,175,366,572,508,314,170,282,744,316,164,69,178,801
218,457,484,161,800,860,911,492,250,898,455,888,252,54,932,745,393,856,363,519
207,923,189,314,182,483,179,730,174,186,324,481,658,494,294,167,492,854,803,778
800,87,644,61,586,517,645,905,190,573,316,855,150,170,304,389,218,979,388,741
846,482,84,326,798,745,926,725,362,176,340,197,165,572,268,912,481,558,335,632
184,773,536,594,945,494,738,401,649,949,404,135,274,467,817,299,853,740,603,926
843,855,551,798,443,586,481,721,809,340,142,570,774,938,150,485,154,299,822,857
272,782,366,666,658,917,731,509,733,371,639,245,585,312,336,805,111,868,642,511
447,888,511,822,822,940,527,909,274,938,867,984,193,274,527,449,487,888,515,560
304,174,393,1,170,444,568,634,395,481,260,586,729,634,694,55,305,531,501,162
629,585,932,813,572,945,598,369,743,375,178,411,397,648,221,805,648,72,817,698
631,554,698,861,906,380,484,70,739,606,359,519,418,111,728,564,935,208,90,383
90,500,825,163,899,532,392,641,571,484,220,877,530,351,368,918,229,337,367,50
171,341,914,323,737,256,647,939,745,138,908,648,690,857,145,774,855,919,745,605
179,906,324,91,365,322,843,512,857,324,139,69,902,823,332,313,776,254,653,457
668,237,456,573,913,503,140,200,283,449,241,148,148,323,635,734,694,143,815,924
84,195,63,216,356,730,457,67,923,654,269,173,646,400,65,664,641,455,400,294
401,373,418,600,848,659,740,59,400,796,418,449,721,993,644,163,875,444,949,87
628,934,497,657,336,325,398,62,384,150,672,335,785,170,305,241,167,361,502,571
458,858,501,491,271,217,569,162,168,205,335,325,744,380,54,303,884,794,916,646
280,498,728,358,587,171,891,525,935,819,843,398,515,671,729,418,257,512,871,591
288,891,658,311,853,166,510,84,502,937,633,360,143,692,374,92,515,393,60,277
447,153,383,332,260,447,694,299,531,490,636,534,166,137,892,858,817,498,654,784
252,799,885,852,856,774,89,154,333,590,338,504,165,378,696,606,53,728,349,537
221,281,278,179,737,813,522,798,355,283,193,570,921,928,264,745,585,241,351,808
556,244,60,858,452,221,655,595,204,603,899,329,417,449,503,894,192,56,980,587
875,780,350,728,889,527,671,790,589,857,520,936,180,942,818,448,558,664,920,819
355,858,531,976,530,135,55,336,894,150,194,905,379,496,338,299,262,247,511,574
182,637,184,865,7,933,55,826,733,738,820,245,566,655,632,564,529,900,538,342
905,509,943,814,798,819,417,485,327,61,160,168,616,210,788,936,788,365,908,497
50,946,380,527,894,203,267,810,906,198,569,803,888,170,555,694,659,70,371,590
591,815,364,401,766,815,275,596,176,634,370,561,505,181,890,138,452,735,518,147
827,683,52,534,656,510,328,323,52,278,815,930,743,137,53,190,903,741,660,875
167,859,260,725,923,917,922,142,339,388,363,508,914,667,790,862,515,282,212,350
161,882,443,265,517,483,776,650,661,499,887,794,302,516,150,412,485,698,820,185
345,487,810,868,871,190,209,507,327,534,86,856,305,877,931,210,121,886,903,567
843,875,362,560,320,17,869,64,948,561,896,248,778,174,54,947,792,386,630,366
916,904,884,91,867,796,862,153,453,449,397,908,485,264,53,848,141,936,889,551
569,740,646,200,792,649,213,719,787,456,933,414,361,526,340,732,63,135,469,865
359,384,221,87,650,396,241,197,281,947,19,418,527,738,172,486,857,282,262,525
854,603,494,532,160,329,162,537,358,887,415,913,487,531,172,177,393,521,940,698
403,535,738,334,827,530,527,495,229,526,512,340,248,170,866,188,691,820,398,822
654,241,630,740,920,485,532,722,479,348,90,51,87,158,241,389,301,531,496,350
547,143,492,534,871,939,303,306,88,247,268,55,363,312,564,344,740,560,277,150
915,823,90,651,852,416,668,207,905,563,249,308,84,338,216,67,346,112,523,924
825,734,211,581,454,811,340,347,207,532,506,400,660,412,328,573,319,146,735,519
540,875,176,220,355,184,885,854,780,572,83,142,181,387,371,603,925,514,654,9
398,402,561,151,608,565,528,850,136,497,939,386,943,919,938,86,946,329,380,367
390,912,651,811,563,63,20,368,146,187,173,538,658,364,938,264,869,194,573,845
154,331,321,244,189,445,88,873,208,650,312,368,744,932,243,345,792,58,995,637
172,813,638,66,859,161,915,921,928,383,587,644,388,183,868,358,319,681,602,567
399,866,603,207,557,172,366,349,707,812,664,806,454,299,593,779,772,651,502,170
310,777,312,917,406,670,874,187,559,945,58,505,393,393,418,666,158,297,811,664
66,936,270,595,515,844,546,491,638,314,381,177,791,805,264,640,342,693,172,160
521,270,906,822,273,269,448,905,456,304,176,330,249,211,492,780,515,539,802,640
135,790,271,772,935,492,300,875,827,896,282,260,891,915,657,879,505,88,283,303
443,275,414,237,888,596,729,938,161,514,147,275,854,497,652,629,366,910,264,922
370,146,402,649,328,859,789,787,794,665,321,810,174,777,889,396,649,389,494,410
642,629,221,538,400,591,84,983,815,692,267,267,266,179,667,564,566,359,689,159
499,806,219,663,690,536,535,664,83,370,531,640,589,988,654,511,260,666,173,531
670,733,900,881,635,313,281,449,179,695,513,397,915,774,532,209,343,375,889,661
654,300,195,921,434,564,143,861,720,893,875,208,860,777,557,305,62,774,71,139
342,916,201,899,741,357,645,363,146,317,630,380,287,370,773,649,174,358,876,667
875,736,866,60,867,308,159,152,296,872,354,241,56,586,656,513,491,933,213,323
564,632,648,503,190,728,270,272,850,666,348,663,263,201,406,206,697,249,504,164
568,592,738,518,277,456,780,635,883,70,218,411,722,403,175,910,334,413,484,175
827,198,282,832,53,111,414,411,329,388,909,208,602,531,745,734,195,52,502,938
493,324,779,691,882,746,335,891,937,594,527,145,167,729,848,315,54,556,731,746
163,153,806,795,246,398,312,505,52,897,880,780,590,519,70,487,533,53,498,896
220,339,843,212,524,596,151,412,853,865,860,496,360,810,559,357,201,746,491,734
137,822,270,870,852,53,730,761,648,165,481,801,414,370,399,519,944,305,343,814
455,303,137,919,166,336,448,532,531,211,504,773,593,698,905,455,171,995,500,603
851,631,742,789,332,205,818,350,386,495,528,544,361,210,693,827,305,870,689,506
111,163,207,780,595,393,874,692,368,300,10,485,220,450,499,860,398,190,593,211
631,871,733,921,864,599,170,653,361,362,211,746,219,258,313,370,193,321,207,188
897,831,929,868,843,342,901,791,450,537,280,445,511,667,719,389,197,360,398,945
375,906,876,211,457,361,373,557,65,164,170,184,794,728,692,22,503,325,395,142
812,360,395,735,69,825,445,904,356,804,336,858,542,366,171,642,504,903,917,939
156,309,731,695,723,450,940,632,793,262,62,638,728,378,186,446,919,263,247,821
534,215,60,854,730,867,163,927,799,994,932,865,670,269,791,857,347,53,744,664
507,373,844,729,451,264,455,283,923,366,514,212,272,378,307,814,410,662,557,531
606,87,594,289,893,772,511,926,111,939,165,314,413,53,650,936,498,263,309,179
788,153,740,318,856,444,337,183,178,632,50,180,245,490,792,443,163,723,489,510
301,140,324,571,884,508,868,872,301,730,798,484,593,147,259,350,700,810,852,692
416,943,853,178,827,565,279,566,317,892,251,857,817,217,538,271,348,63,264,140
378,346,699,393,903,943,534,880,151,302,414,397,819,933,689,150,893,397,598,58
277,311,645,525,904,141,112,697,347,151,877,376,149,643,358,793,929,773,881,310
855,488,659,250,513,918,64,484,889,488,360,91,51,274,932,735,880,54,737,369
732,89,976,659,299,772,494,185,268,369,891,513,305,342,188,264,86,945,657,732
417,155,392,689,171,186,53,982,931,85,803,147,376,825,499,945,158,719,193,904
206,397,910,722,591,359,315,268,194,356,606,948,728,822,805,198,63,292,791,140
719,664,490,521,562,938,592,404,401,276,316,313,637,803,177,937,453,794,851,282
587,530,400,165,944,873,350,696,389,930,636,260,780,879,383,825,660,655,305,656
890,914,67,299,824,914,360,211,68,186,206,899,705,443,246,361,734,568,846,909
379,976,403,160,939,737,817,777,263,742,416,506,325,111,597,213,887,405,330,507
211,641,930,320,790,719,362,90,792,323,696,519,925,599,92,173,466,592,923,142
495,529,164,911,505,668,357,390,88,731,628,630,170,519,910,416,69,335,667,473
616,746,332,354,905,730,83,59,903,525,313,571,304,925,56,844,643,383,793,909
556,668,601,848,397,175,260,152,727,672,787,664,788,281,369,199,453,573,574,149
216,174,851,71,790,366,785,213,594,640,746,216,656,729,207,157,86,570,176,731
384,606,204,809,199,303,285,779,509,493,52,217,391,451,596,69,885,629,69,929
844,157,61,571,186,184,728,831,646,898,146,902,661,54,391,219,928,62,204,218
271,391,809,504,852,157,986,853,889,413,940,791,137,271,628,221,493,813,932,365
482,190,329,886,921,162,802,914,787,532,452,790,873,210,657,810,595,235,395,323
821,339,199,325,414,150,16,259,566,730,496,799,445,371,249,177,936,511,88,135
903,147,384,485,70,300,268,345,830,631,318,269,787,174,937,500,360,511,90,910
84,322,277,178,280,153,915,191,92,571,327,822,646,65,413,638,540,715,886,245
455,465,316,696,515,112,265,788,533,367,205,193,641,144,282,651,530,190,601,604
218,802,398,351,142,886,357,932,210,638,152,734,90,53,787,343,531,873,17,737
339,90,808,176,322,316,157,598,302,590,327,775,218,151,806,372,165,478,184,299
900,527,921,413,884,573,380,221,482,942,566,778,879,668,144,161,567,208,659,326
365,854,372,112,176,457,416,569,152,871,740,809,652,371,147,90,784,735,851,788
386,388,573,919,277,69,608,803,813,933,905,855,862,337,326,719,733,563,667,450
593,187,825,503,142,187,559,719,175,193,495,849,564,61,524,511,593,737,867,605
199,395,635,487,910,822,944,864,415,661,988,55,153,375,248,187,196,641,819,160
389,878,304,196,904,395,716,628,925,135,145,593,632,495,649,598,209,86,812,859
653,406,798,497,806,556,84,320,202,278,363,787,594,824,305,585,208,192,213,395
55,691,789,88,876,910,594,331,274,862,51,563,875,370,614,900,569,947,172,666
149,736,926,525,16,929,263,52,444,645,935,83,452,347,815,509,806,454,152,868
307,605,265,638,578,797,864,855,414,895,372,495,849,65,318,926,888,528,372,646
189,941,53,531,699,415,342,635,633,244,805,193,794,180,976,339,54,456,196,316
369,322,332,874,468,52,197,518,507,356,489,694,268,796,351,655,206,655,907,244
347,382,161,675,628,745,689,349,662,776,893,787,210,854,411,376,855,510,111,155
322,597,266,874,448,774,306,916,905,416,550,820,249,483,663,378,931,65,793,281
357,149,598,734,873,344,802,943,745,850,218,61,479,873,58,203,268,371,279,348
261,154,947,178,866,360,733,484,195,806,342,312,942,334,252,189,804,221,556,912
245,338,858,532,804,565,892,445,491,889,329,190,264,599,347,567,901,879,321,929
452,1,213,593,847,850,372,898,660,414,738,947,497,485,795,390,245,632,887,814
152,362,445,694,860,272,848,363,2,944,334,926,450,823,943,249,142,318,190,907
188,919,70,513,56,501,148,164,600,401,211,353,219,321,449,521,897,71,792,303
989,592,493,60,369,655,86,263,772,779,181,537,263,180,450,173,370,84,596,344
491,671,934,539,513,163,830,111,314,647,266,798,667,179,325,849,921,356,864,204
331,491,181,921,193,925,644,178,411,532,643,874,68,87,601,555,788,343,890,217
218,945,341,669,802,143,571,140,188,154,899,777,573,88,302,257,444,587,411,908
559,572,365,448,179,930,668,636,58,354,142,7,403,318,387,382,157,388,188,447
302,365,799,547,211,872,729,55,585,904,799,189,922,152,645,925,561,273,313,446
892,213,531,257,539,855,316,242,349,886,242,248,153,822,670,176,586,670,386,310
556,215,50,270,668,484,140,333,867,55,326,944,70,414,454,83,510,626,569,283
179,455,501,670,902,185,536,574,376,900,195,919,982,629,148,884,662,487,845,331
65,794,491,211,322,388,888,343,782,644,135,558,564,263,488,666,335,275,672,206
281,252,887,594,52,203,194,587,606,155,777,843,451,412,851,56,196,194,794,498
812,640,850,777,175,450,918,160,418,165,507,304,532,445,385,373,504,492,499,712
451,153,209,486,153,500,645,328,324,912,979,691,657,490,381,572,199,931,86,336
796,603,908,792,228,525,58,807,363,572,657,66,350,55,331,515,484,775,456,137
280,265,910,174,128,343,356,775,200,372,112,598,447,56,154,516,859,268,265,938
318,628,356,396,452,266,742,906,180,273,797,661,309,327,310,201,888,872,622,320
84,50,311,898,363,320,208,341,358,672,354,995,818,731,199,791,176,810,740,327
494,454,931,721,394,918,507,553,656,167,210,662,730,530,807,695,647,917,863,356
737,193,215,937,53,347,54,381,793,271,632,389,69,526,162,374,699,324,7,333
160,716,746,199,306,629,873,628,163,903,249,585,695,281,403,322,630,261,528,150
327,797,533,660,669,638,924,532,307,53,495,24,396,691,908,185,516,283,720,845
574,216,58,458,202,221,793,164,454,906,457,182,62,696,943,376,300,312,741,919
344,358,691,566,794,316,592,298,361,654,731,189,819,573,493,250,296,894,194,744
385,873,483,249,699,808,736,166,899,789,486,900,777,646,345,148,739,762,658,63
662,923,853,888,256,259,242,87,589,332,821,876,143,516,367,213,91,935,330,794
311,532,802,374,355,526,337,795,662,161,475,646,631,147,561,63,452,194,871,55
216,165,263,561,268,896,283,699,327,495,869,332,527,701,260,729,245,145,698,742
880,731,453,593,334,919,564,639,335,924,905,65,363,942,780,247,733,411,921,719
373,908,601,315,914,656,825,928,351,902,859,734,986,537,639,823,816,634,181,859
500,137,378,918,515,923,411,735,415,819,599,346,146,400,459,899,906,798,859,518
670,622,590,346,793,518,396,571,810,790,168,866,486,948,602,91,221,283,337,849
277,452,731,532,61,266,391,575,503,397,569,825,562,71,298,911,364,175,635,312
265,322,849,816,501,821,910,928,909,15,512,539,205,396,564,516,538,851,851,642
271,55,901,353,313,386,498,408,383,58,412,337,211,572,217,65,804,917,449,518
283,364,187,806,153,891,279,372,350,502,195,338,454,412,538,446,854,864,721,609
778,366,398,596,892,867,412,195,274,812,535,883,921,51,353,340,933,83,61,598
788,404,934,21,246,888,654,539,145,418,150,658,510,91,281,930,788,932,910,282
634,156,798,159,565,487,592,633,390,910,139,854,277,140,585,2,332,513,492,932
380,198,209,696,417,385,50,329,804,745,935,516,591,735,719,694,768,731,508,111
174,734,268,301,854,745,518,615,345,312,244,565,633,506,599,789,773,352,886,178
891,216,324,184,527,449,572,535,378,911,339,659,979,928,560,823,773,318,814,386
565,58,253,415,177,402,86,206,201,192,948,395,648,694,628,899,865,561,401,323
863,340,557,324,136,986,245,167,482,354,596,56,89,374,178,690,242,849,637,346
341,601,416,697,308,777,188,785,150,526,263,903,915,661,897,734,164,497,510,137
92,599,932,895,325,499,199,139,561,191,668,697,511,329,315,815,833,887,813,443
402,396,495,852,386,453,148,84,826,800,263,564,52,606,659,871,698,185,266,522
645,878,352,812,865,776,881,902,262,917,810,205,165,314,606,368,739,644,853,559
517,527,452,807,306,68,181,523,216,628,874,719,605,269,266,155,897,496,817,369
507,927,927,220,378,775,865,380,339,631,366,917,491,643,156,574,391,543,51,515
906,244,787,280,194,806,813,213,523,890,745,671,665,377,336,449,169,565,630,909
259,791,87,329,191,275,540,71,155,176,362,874,217,320,827,517,774,782,398,70
496,820,812,332,706,370,417,857,649,500,308,559,794,394,181,58,777,92,413,383
651,368,357,324,153,244,385,868,70,667,280,372,742,314,556,800,298,578,492,561
160,159,324,902,340,158,455,205,370,875,986,787,193,85,507,650,333,663,843,319
744,391,514,399,936,65,928,197,678,450,586,662,732,632,654,359,640,203,272,443
170,362,136,567,303,596,186,287,183,663,199,811,742,603,338,360,275,918,169,808
402,330,894,481,802,218,199,906,147,492,364,315,697,821,842,150,665,720,728,455
56,184,204,629,586,197,354,519,318,697,694,742,176,338,664,900,140,518,71,880
483,932,861,559,212,503,663,394,863,918,560,887,745,322,881,940,896,60,167,344
629,590,176,650,719,374,152,518,409,930,902,643,266,922,205,375,196,387,875,948
556,63,800,148,78,886,169,697,516,663,158,185,341,889,499,802,167,851,342,871
399,402,946,386,175,640,886,682,633,493,507,371,670,145,892,162,166,198,632,214
560,915,526,498,923,305,667,216,602,864,519,186,924,326,241,905,329,407,824,163
417,0,138,596,495,797,189,64,404,799,670,381,658,912,482,161,651,537,270,354
139,815,530,914,592,318,337,447,449,911,809,184,263,264,781,826,328,731,538,338
302,448,272,163,505,313,691,940,392,878,817,258,800,905,642,738,349,856,264,932
493,307,64,283,86,925,153,815,600,850,511,698,280,520,305,904,493,179,531,367
357,817,648,386,513,806,592,701,735,372,573,564,855,214,366,848,353,816,136,264
201,631,313,145,538,912,447,363,194,796,561,668,777,306,780,488,323,646,251,451
934,66,490,826,314,168,821,603,539,417,735,864,902,895,358,197,998,777,307,525
170,60,858,249,557,197,476,396,416,810,932,737,396,929,602,198,529,657,450,871
68,390,153,452,377,907,231,587,187,332,778,385,112,690,513,874,906,357,380,393
492,822,261,729,548,138,655,283,485,640,497,920,482,897,320,810,183,175,488,698
902,286,366,890,405,603,911,259,499,940,374,271,376,515,694,904,948,653,516,743
595,506,741,630,948,401,915,884,549,386,847,166,914,694,690,569,368,371,777,388
445,245,145,821,633,141,417,948,327,204,147,149,325,507,857,890,73,537,191,380
506,734,638,342,534,55,719,473,369,322,945,894,365,803,889,404,405,179,663,145
383,857,774,404,674,338,350,495,187,884,304,507,862,948,155,207,259,61,651,362
147,338,892,348,629,210,488,243,299,451,162,161,689,657,280,365,581,302,518,137
721,274,947,627,570,892,489,328,221,318,443,557,50,648,250,166,532,186,629,944
539,532,191,984,112,282,801,200,913,336,948,739,815,777,161,50,742,804,159,212
67,343,887,712,273,500,661,141,57,172,567,356,65,515,788,631,693,922,897,373
196,512,803,383,864,802,694,348,417,826,591,8,797,194,191,794,206,862,159,739
489,519,484,399,276,774,270,944,176,173,263,908,522,377,744,593,196,162,416,655
269,384,55,177,142,699,741,225,807,497,908,314,744,586,221,778,395,276,390,151
694,211,643,822,773,348,329,174,269,866,276,242,565,856,167,919,555,343,776,243

77
2020/16/prog.py Normal file
View File

@ -0,0 +1,77 @@
import re
#################################################################################
# #
# DISCLAIMER: THE SOLUTION I FOUND THE THIS DAY IS HORRIBLE, I AIN'T PROUD OF #
# IT AT ALL (IT WORKS THO) #
# #
#################################################################################
def get_input(sample = False, part = 1):
with open(f"sample_p{part}" if sample else "input", "r") as f:
ret = {}
data = f.read().split("\n\n")
ranges = {}
for line in data[0].split("\n"):
name, range = get_range(line)
ranges[name] = range
ret["ranges"] = ranges
ret["my ticket"] = [int(v) for v in data[1].split("\n")[1].split(",")]
ret["nearby tickets"] = [[int(v) for v in line.split(",")] for line in data[2].split("\n")[1:]]
return ret
def get_range(range_str: str):
range_re = re.compile(r'(.+): (\d+)-(\d+) or (\d+)-(\d+)')
name, min_1, max_1, min_2, max_2 = range_re.match(range_str).groups()
return name, [range(int(min_1), int(max_1) + 1), range(int(min_2), int(max_2) + 1)]
def get_result(inp: dict, part = 1):
invalid_values = []
invalid_ticket_indices = set()
for i_ticket, ticket in enumerate(inp["nearby tickets"]):
for value in ticket:
is_value_valid = False
for r in inp["ranges"].values():
if value in r[0] or value in r[1]:
is_value_valid = True
break
if not is_value_valid:
invalid_values.append(int(value))
invalid_ticket_indices.add(i_ticket)
if part == 1:
return sum(invalid_values)
valid_tickets = [ticket for i, ticket in enumerate(inp['nearby tickets']) if i not in invalid_ticket_indices]
range_to_index = {name: {i for i in range(len(valid_tickets[0]))} for name in inp["ranges"]}
for ticket in valid_tickets:
for i, value in enumerate(ticket):
for name, rng in inp["ranges"].items():
if not (value in rng[0] or value in rng[1]):
range_to_index[name].discard(i)
# I'M SO SORRY FOR THIS WHILE LOOP, BUT I FOUND NO OTHER WAY TO "MUTUALLY EXCLUDE" EVERY SET OF INDICES FROM ONE ANOTHER... :/
while list(map(lambda x: len(x), range_to_index.values())) != [1]*len(range_to_index):
for name, indices in range_to_index.items():
if len(indices) == 1:
for i_name, i_indices in range_to_index.items():
if name != i_name:
range_to_index[i_name] = i_indices - indices
re_dep = re.compile(r'^departure ')
ret = 1
for name, index in range_to_index.items():
if re_dep.match(name) != None:
ret *= inp["my ticket"][index.pop()]
return ret
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

12
2020/16/sample_p1 Normal file
View File

@ -0,0 +1,12 @@
class: 1-3 or 5-7
row: 6-11 or 33-44
seat: 13-40 or 45-50
your ticket:
7,1,14
nearby tickets:
7,3,47
40,4,50
55,2,20
38,6,12

11
2020/16/sample_p2 Normal file
View File

@ -0,0 +1,11 @@
class: 0-1 or 4-19
row: 0-5 or 8-19
seat: 0-13 or 16-19
your ticket:
11,12,13
nearby tickets:
3,9,18
15,1,5
5,14,9

15
2020/16/test.py Normal file
View File

@ -0,0 +1,15 @@
from prog import *
import unittest
class Methods(unittest.TestCase):
pass
class Result(unittest.TestCase):
def test_p1(self):
inp = get_input(sample = True)
self.assertEqual(get_result(self.inp), 71)
def test_p2(self):
inp = get_input(sample = True, part = 2)
self.assertEqual(get_result(inp, part = 2), 71)

Binary file not shown.

Binary file not shown.

9
2020/17/input Normal file
View File

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

81
2020/17/prog.py Normal file
View File

@ -0,0 +1,81 @@
def get_input(sample = False):
with open('sample' if sample else 'input', 'r') as f:
ret = {0: {0: {}}}
lines = f.readlines()
for y, row in enumerate(lines, start = -len(lines) // 2):
ret[0][0][y] = {}
row = row.strip()
for x, cube in enumerate(row, start = -len(row) // 2):
ret[0][0][y][x] = cube
return ret
def count_actives(space: dict):
ret = 0
for w in space.values():
for z in w.values():
for y in z.values():
for x in y.values():
if x == "#":
ret += 1
return ret
def count_active_neighbours(space: dict, center_x, center_y, center_z, center_w):
ret = 0
for w in range(center_w - 1, center_w + 2):
if w not in space.keys(): continue
for z in range(center_z - 1, center_z + 2):
if z not in space[w].keys(): continue
for y in range(center_y - 1, center_y + 2):
if y not in space[w][z].keys(): continue
for x in range(center_x - 1, center_x + 2):
if x in space[w][z][y].keys() and (x, y, z, w) != (center_x, center_y, center_z, center_w) and space[w][z][y][x] == "#":
ret += 1
return ret
def print_space(space: dict):
for w, time in sorted(space.items()):
for z, plain in sorted(space[w].items()):
print(f"\t{z = } {w = }")
for y, row in sorted(plain.items()):
print(f"\t{''.join([value for key, value in sorted(row.items())])}")
print()
def get_result(space_4d: list, part = 1):
for cycle in range(6):
next_space_4d = {}
for w in range(min(space_4d) - 1, max(space_4d) + 2) if part == 2 else [0]:
space = space_4d[w] if w in space_4d else {z_0 : {y_0: {x_0: '.' for x_0 in space_4d[0][0][0]} for y_0 in space_4d[0][0]} for z_0 in space_4d[0]}
next_space_4d[w] = {}
for z in range(min(space) - 1, max(space) + 2):
plain = space[z] if z in space else {y_0: {x_0: '.' for x_0 in space[0][0]} for y_0 in space[0]}
next_space_4d[w][z] = {}
for y in range(min(plain) - 1, max(plain) + 2):
row = plain[y] if y in plain else {x_0: '.' for x_0 in space[0][0]}
next_space_4d[w][z][y] = {}
for x in range(min(row) - 1, max(row) + 2):
cube = row[x] if x in row else '.'
count = count_active_neighbours(space_4d, x, y, z, w)
if cube == "#":
if count in [2, 3]:
next_cube = "#"
else:
next_cube = "."
else:
if count == 3:
next_cube = "#"
else:
next_cube = "."
next_space_4d[w][z][y][x] = next_cube
space_4d = next_space_4d
return count_actives(space_4d)
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

3
2020/17/sample Normal file
View File

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

16
2020/17/test.py Normal file
View File

@ -0,0 +1,16 @@
from prog import *
import unittest
class Methods(unittest.TestCase):
pass
class Result(unittest.TestCase):
def setUp(self):
self.inp = get_input(sample = True)
def test_p1(self):
self.assertEqual(get_result(self.inp), 112)
def test_p2(self):
self.assertEqual(get_result(self.inp, part = 2), 848)

Binary file not shown.

Binary file not shown.

375
2020/18/input Normal file
View File

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

55
2020/18/prog.py Normal file
View File

@ -0,0 +1,55 @@
import re
calc_re = re.compile(r'(\d+) ([+*]) (\d+)')
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [line.strip() for line in f.readlines()]
def find_closing_bracket_starting_at(index: int, string: str):
open_br = 0
for i, c in enumerate(string[index:], start=index):
if c == "(":
open_br += 1
elif c == ")":
open_br -= 1
if open_br == 0:
return i
def evaluate_advanced(calc: str):
starting_bracket = calc.find("(")
if starting_bracket != -1:
end_bracket = find_closing_bracket_starting_at(starting_bracket, calc)
return evaluate_advanced(calc[:starting_bracket] + str(evaluate_advanced(calc[starting_bracket+1:end_bracket])) + calc[end_bracket+1:])
additions = [external_group for external_group, internal_group in re.findall(r'((\d+ \+ )+\d+)', calc)]
for add in additions:
calc = calc.replace(add, str(eval(add)), 1)
return eval(calc)
def evaluate_l2r(calc: str):
starting_bracket = calc.find("(")
if starting_bracket != -1:
end_bracket = find_closing_bracket_starting_at(starting_bracket, calc)
return evaluate_l2r(calc[:starting_bracket] + str(evaluate_l2r(calc[starting_bracket+1:end_bracket])) + calc[end_bracket+1:])
match = calc_re.match(calc)
first, operation, second = match.groups()
first, second = int(first), int(second)
rest = calc[match.end():]
if operation == "+":
new = first + second
elif operation == "*":
new = first * second
return new if len(rest) == 0 else evaluate_l2r(str(new) + rest)
def get_result(inp: list, part = 1):
return sum((evaluate_l2r(op) if part == 1 else evaluate_advanced(op)) for op in inp)
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

4
2020/18/sample_p1 Normal file
View File

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

5
2020/18/sample_p2 Normal file
View File

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

54
2020/18/test.py Normal file
View File

@ -0,0 +1,54 @@
from prog import *
import unittest
class Methods(unittest.TestCase):
def test_bracket(self):
self.assertEqual(find_closing_bracket_starting_at(4, "1 + (1 + 2)"), 10)
self.assertEqual(find_closing_bracket_starting_at(0, "(1 + 2)"), 6)
self.assertEqual(find_closing_bracket_starting_at(1, "((1 + 2) + 2)"), 7)
self.assertEqual(find_closing_bracket_starting_at(0, "((1 + 2) + 2)"), 12)
def test_evaluate_l2r_simple(self):
self.assertEqual(evaluate_l2r("1 + 1"), 2)
self.assertEqual(evaluate_l2r("51 + 24"), 75)
self.assertEqual(evaluate_l2r("223 * 23"), 5129)
def test_evaluate_adv_simple(self):
self.assertEqual(evaluate_advanced("1 + 1"), 2)
self.assertEqual(evaluate_advanced("51 + 24"), 75)
self.assertEqual(evaluate_advanced("223 * 23"), 5129)
def test_evaluate_l2r_medium(self):
self.assertEqual(evaluate_l2r("1 + 1 + 1"), 3)
self.assertEqual(evaluate_l2r("12 + 278 + 3"), 293)
self.assertEqual(evaluate_l2r("22 * 2 + 1"), 45)
self.assertEqual(evaluate_l2r("3 + 2 * 10"), 50)
def test_evaluate_adv_medium(self):
self.assertEqual(evaluate_advanced("11 + 12 + 13 * 21 + 22 * 31 + 32 + 33 + 34"), 201240)
self.assertEqual(evaluate_advanced("12 + 278 + 3"), 293)
self.assertEqual(evaluate_advanced("22 * 2 + 1"), 66)
self.assertEqual(evaluate_advanced("3 + 2 * 10"), 50)
def test_evaluate_l2r_hard(self):
self.assertEqual(evaluate_l2r("2 * 3 + (4 * 5)"), 26)
self.assertEqual(evaluate_l2r("5 + (8 * 3 + 9 + 3 * 4 * 3)"), 437)
self.assertEqual(evaluate_l2r("5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"), 12240)
self.assertEqual(evaluate_l2r("((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2"), 13632)
def test_evaluate_adv_hard(self):
self.assertEqual(evaluate_advanced("3 * 3 + (1 * 1 * 1)"), 12)
self.assertEqual(evaluate_advanced("1 + (2 * 3) + (4 * (5 + 6))"), 51)
self.assertEqual(evaluate_advanced("2 * 3 + (4 * 5)"), 46)
self.assertEqual(evaluate_advanced("5 + (8 * 3 + 9 + 3 * 4 * 3)"), 1445)
self.assertEqual(evaluate_advanced("5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))"), 669060)
self.assertEqual(evaluate_advanced("((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2"), 23340)
class Result(unittest.TestCase):
def test_p1(self):
self.assertEqual(get_result(get_input(sample = True)), 26335)
def test_p2(self):
self.assertEqual(get_result(get_input(sample = True, part = 2), part = 2), 693942)

1000
2020/2/input Normal file

File diff suppressed because it is too large Load Diff

56
2020/2/prog.py Normal file
View File

@ -0,0 +1,56 @@
def get_file_input(filename: str):
ret = set()
with open(filename, "r") as f:
for line in f.readlines():
rule, *pwd = line.split(":")
pwd = "".join(pwd).strip()
ret.add((pwd, rule))
return ret
def main(use_sample_input = True):
sample = {
("abcde", "1-3 a"),
("cdefg", "1-3 b"),
("ccccccccc", "2-9 c"),
}
expected_result = 2
res = get_result(sample if use_sample_input else get_file_input("input"))
if use_sample_input:
return f"{res} {res==expected_result}"
else:
return res
def check_n_chars(pwd: str, char: str, n_min: int, n_max: int) -> bool: # part 1
n = 0
for c in pwd:
if c == char:
n += 1
return n_min <= n and n <= n_max
def check_pos_chars(pwd:str, char: str, pos1: int, pos2: int) -> bool: # part 2
return (pwd[pos1] == char) != (pwd[pos2] == char)
def is_pwd_ok(pwd: str, rule: str) -> bool:
*delimiters, char = rule.split(" ")
n_min, n_max = "".join(delimiters).split("-")
n_min = int(n_min)
n_max = int(n_max)
return check_pos_chars(pwd, char, n_min - 1, n_max - 1)
def get_result(data: dict) -> int:
ret = 0
for pwd, rule in data:
b = is_pwd_ok(pwd, rule)
ret += 1 if b else 0
return ret
print(main(use_sample_input = False))

323
2020/3/input Normal file
View File

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

69
2020/3/prog.py Normal file
View File

@ -0,0 +1,69 @@
def get_file_input(filename: str):
ret = []
with open(filename, "r") as f:
for line in f.readlines():
ret.append(line.strip())
return ret
def main(use_sample_input = True, part = 1):
sample = [
"..##.......",
"#...#...#..",
".#....#..#.",
"..#.#...#.#",
".#...##..#.",
"..#.##.....",
".#.#.#....#",
".#........#",
"#.##...#...",
"#...##....#",
".#..#...#.#"
]
s = sample if use_sample_input else get_file_input("input")
if part == 1:
expected_result = 7
res = get_result(s, 3, 1)
else:
expected_result = 336
slopes = {
(1, 1),
(3, 1),
(5, 1),
(7, 1),
(1, 2)
}
tmp = []
for slope in slopes:
tmp.append(get_result(s, *slope))
res = mult_all(*tmp)
if use_sample_input:
return f"{res} {res==expected_result}".upper()
else:
return res
def mult_all(*ns: int):
ret = 1
for n in ns:
ret *= n
return ret
def get_result(l: list, inc_x: int, inc_y: int):
ret = 0
x = 0
y = 0
while y < len(l):
if l[y][x] == "#":
ret += 1
x += inc_x
x %= len(l[0])
y += inc_y
return ret
print(main(use_sample_input = False, part = 2))

Binary file not shown.

1138
2020/4/input Normal file

File diff suppressed because it is too large Load Diff

81
2020/4/prog.py Normal file
View File

@ -0,0 +1,81 @@
import re
def extract_passports(passports: list):
ret = []
kv_re = re.compile(r'(\w+):(#?\w+)')
for passport in passports:
dic = {}
for key, val in kv_re.findall(passport):
dic[key] = val
ret.append(dic)
return ret
def get_input(sample = False):
with open("sample" if sample else "input", "r") as f:
content = f.read()
passports = content.split("\n\n")
return extract_passports(passports)
def is_passport_valid_1(passport: dict):
fields = {"byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"}
keys = set(passport.keys())
return keys == fields or keys == fields | {"cid"}
between = lambda m1, x, m2: int(m1) <= int(x) and int(x) <= int(m2);
def is_height_valid(height: str):
h_re = re.compile(r'^(\d+)(cm|in)$')
if h_re.match(height) == None: return False
number, measure = h_re.findall(height)[0]
return (measure == "cm" and between(150, number, 193)) or (measure == "in" and between(59, number, 76))
def is_passport_valid_2(passport: dict):
is_four_digits = lambda x: re.match(r'^\d{4}$', x) != None
rules = {"byr": lambda x: is_four_digits(x) and between(1920, x, 2002),
"iyr": lambda x: is_four_digits(x) and between(2010, x, 2020),
"eyr": lambda x: is_four_digits(x) and between(2020, x, 2030),
"hgt": is_height_valid,
"hcl": lambda x: re.match(r'^#[a-f0-9]{6}$', x) != None,
"ecl": lambda x: x in ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"],
"pid": lambda x: re.match(r'^\d{9}$', x) != None,
"cid": lambda x: True}
# try:
# print(passport["hcl"], rules["hcl"](passport["hcl"]))
# except KeyError as e:
# pass
for key, val in passport.items():
if not rules[key](val):
return False
return True
def get_result(passports: list, part = 1):
ret = 0
print(f"{len(passports)=}")
for p in passports:
if (part == 1 and is_passport_valid_1(p)) or (part == 2 and is_passport_valid_2(p) and is_passport_valid_1(p)):
ret += 1
return ret
def main(sample = False, part = 1):
inp = get_input(sample = sample)
res = get_result(inp, part = part)
if sample:
expected = 2 if part == 2 else 0
print(f"{res=}")
print(res == expected)
else:
print(res)
main(sample = False, part = 2)

13
2020/4/sample 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

50
2020/4/test.py Normal file
View File

@ -0,0 +1,50 @@
from prog import get_input
expected = [
{
'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',
},
]
out = get_input(sample = True)
for o, e in zip(out, expected):
print(o)
print(e)
print(out == expected)

Binary file not shown.

Binary file not shown.

824
2020/5/input.prod Normal file
View File

@ -0,0 +1,824 @@
FFFFBFBLLR
BFBFFBBLLR
BBFFFFBLRR
FBFBFFFRLL
BFFBFFFRRR
BFBFBFFRLR
FFFBBBBLRL
BFFFFBFLLL
FFFFBBFLLR
BBFFBFFRRR
FBBFBBFLRL
BFBFFBFLRR
FBFFBFFLLL
FFFBFFFRLR
FFFBFBBLLR
BBFFBFFLRL
FFFFFBBRLR
BFFBFBBLLR
FFBBBBBLRR
FBBFFBBLLR
FFFFFBBLLR
FBBFFFBRLR
FFBFBBFRRR
FBBFFFFLRL
FFBFBBFLLR
BFBBBBFRRL
FFFFBBBLLR
FFBFFFFRLL
FFBBFFBLRL
BBFFFBBRLR
FBBF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BFFBFFRRR
FFFFFBFRLL
FBFBBFFRRL
FFBBFBBLRR
BBFFFFFLLR
FFBBFFFRRR
FFFBBFBLLL
FBFBBBFLLR
FFFFBBBRRL
BFBFFBBRLR
FBFBBBFRRR
FFBBBFFRRL
FFFBBFFRRL
FBFBBFFLRR
FBFFBFBRRL
BBFFFBBLRR
FFBBBBBRRL
FBFBBBFRLL
BFBFFFBRLR
FBFBBFFLLL
BFBBBBFRLL
FBBBBFFLLL
FBFFFFBRLL
FFBBFBFLLL
FBFFFBFLRR
FFFBFFBRLL
FFBBBFBLRR
FFBBFFBRRL
FFBBFBBLLL
FFBBFBBRLR
FFFFBFBLRR
BFBBFBFRLR
BFFFBFBRLL
BBFFFBFRLL
FFFBBFBLRR
FBBFBFFRLR
FBBBFFFRRL
FFBBBBBRRR
FBBBFBFRLL
FBBBBFFRLL
FFBFBBFRLL
BFFBBFBRLL
FFBFFBFRRR
FFBBBBBLLL
BFFFBFBLRL
FBBBBBFLLL
FBBFFBFLLL
BBFFBFFRLL
FBFFFBFLLL

47
2020/5/prog.py Normal file
View File

@ -0,0 +1,47 @@
def get_input(sample = False):
filename = "sample" if sample else "input"
with open(filename + ".prod", "r") as f:
return [line.strip() for line in f.readlines()]
def char_to_bin(char: str):
if char not in ["F", "B", "L", "R"]:
raise ValueError(f"Character `{char=}` cannot be transformed into binary")
return 0 if char == "F" or char == "L" else 1
def seat_to_bin(seat: str):
if len(seat) == 1:
return char_to_bin(seat)
return char_to_bin(seat[0])*2**(len(seat)-1) + seat_to_bin(seat[1:])
def seats_to_binary_list(seats: list):
return [seat_to_bin(seat) for seat in seats]
def get_result(seats: list, part = 1):
if part == 1:
return max(seats)
else:
candidates = []
seats.sort()
prev = seats[0]
for i in range(1, len(seats)):
next = seats[i]
if prev + 2 == next:
candidates.append(prev + 1)
prev = next
return candidates
def main(sample = False, part = 1):
inp = seats_to_binary_list(
get_input(sample = sample)
)
return get_result(inp, part=part)
print(main(part = 2))

3
2020/5/sample.prod Normal file
View File

@ -0,0 +1,3 @@
BFFFBBFRRR
FFFBBBFRRR
BBFFBBFRLL

26
2020/5/test.py Normal file
View File

@ -0,0 +1,26 @@
from prog import seat_to_bin
seats = ["FFFF", # 0000 = 0
"FFFB", # 0001 = 1
"FFBF", # 0010 = 2
"FFBB", # 0011 = 3
"FBFF", # 0100 = 4
"FBFB", # 0101 = 5
"FBBF", # 0110 = 6
"FBBB", # 0111 = 7
"BFFF", # 1000 = 8
"BFFB", # 1001 = 10
"BFBF", # 1010 = 11
"BFBB", # 1011 = 12
"BBFF", # 1100 = 13
"BBFB", # 1101 = 14
"BBBF", # 1110 = 15
"BBBB", # 1111 = 16
]
expected = list(range(17))
for v, e in zip(seats, expected):
actual = seat_to_bin(v)
if actual != e:
print(v, actual, e)

Binary file not shown.

2084
2020/6/input Normal file

File diff suppressed because it is too large Load Diff

61
2020/6/prog.py Normal file
View File

@ -0,0 +1,61 @@
def get_input(sample = False):
ret = []
with open("sample" if sample else "input", "r") as f:
group = []
for line in f.readlines():
if line == "\n": # empty line
ret.append(group)
group = []
else:
group.append(line.strip())
ret.append(group) # add last group
return ret
def list_of_string_to_list(s: set):
ret = []
for string in s:
ret += list(string)
return ret
def grouped_answers(answers: list):
ret = []
start_i = 0
prev = answers[start_i]
for cur_i in range(1, len(answers)):
cur = answers[cur_i]
if prev != cur:
ret.append(answers[start_i:cur_i])
start_i = cur_i
prev = cur
ret.append(answers[start_i:]) # add last answer
return ret
def list_of_string_to_set(s: set):
ret = set()
for string in s:
ret |= set(string)
return ret
def get_result(inp: list, part = 1):
ret = 0
for group in inp:
if part == 1:
ret += len(list_of_string_to_set(group))
else:
group_len = len(group)
splitted_answers = list_of_string_to_list(group)
splitted_answers.sort()
ga = grouped_answers(splitted_answers)
ret += sum(map(lambda x: int(len(x) == group_len), ga))
return ret
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

15
2020/6/sample Normal file
View File

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

23
2020/6/test.py Normal file
View File

@ -0,0 +1,23 @@
from prog import *
inp = get_input(sample = True)
expected_inp = [
["abc"],
["a", "b", "c"],
["ab", "ac"],
["a", "a", "a", "a"],
["b"]
]
expected_result_1 = 11
expected_result_2 = 6
print(inp == expected_inp)
print(get_result(inp) == expected_result_1)
print(get_result(inp, part = 2) == expected_result_2)

Binary file not shown.

594
2020/7/input Normal file
View File

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

79
2020/7/prog.py Normal file
View File

@ -0,0 +1,79 @@
import re
import json
my_bag = "shiny gold"
def get_input(sample = False, sample_number: int = 1):
with open("sample_%d" % sample_number if sample else "input", "r") as f:
return [line.strip() for line in f.readlines()]
def split_n_bags(string: str):
zero_bags = "no other"
if string == zero_bags:
return "", 0
for i in range(len(string)):
if string[i] == " ":
return string[i+1:], int(string[:i])
def parse_input(lines: list):
ret = {}
bag_re = re.compile(" ?bags?[ ,.]?")
for line in lines:
outer, inner = line.split("contain ")
outer = bag_re.sub("", outer)
inner = [bag_re.sub("", x) for x in inner.split(", ")]
if outer not in ret:
ret[outer] = {}
children = {}
for items in inner:
bag, n = split_n_bags(items)
if n != 0:
children[bag] = n
if len(children) > 0:
ret[outer]["children"] = children
for child in children:
if child not in ret: ret[child] = {}
if "parents" not in ret[child]: ret[child]["parents"] = set()
ret[child]["parents"].add(outer)
return ret
def fetch_parents_of(child: str, data: dict):
if "parents" not in data[child]:
return [child]
parents = data[child]["parents"]
parents_total = [child] if child != my_bag else []
for parent in parents:
parents_total.extend(fetch_parents_of(parent, data))
return parents_total
def count_parents_of(child: str, data: dict):
return len(set(fetch_parents_of(child, data)))
def count_children_of(parent: str, data: dict):
if "children" not in data[parent]:
return 0
children = data[parent]["children"]
return sum([number + number * count_children_of(child, data) for child, number in children.items()])
def get_result(data: dict, sample: bool = False, part: int = 1):
if part == 1:
return count_parents_of(my_bag, data)
else:
return count_children_of(my_bag, data)
if __name__ == "__main__":
print(get_result(parse_input(get_input()), part = 2))

9
2020/7/sample_1 Normal file
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.

7
2020/7/sample_2 Normal file
View File

@ -0,0 +1,7 @@
shiny gold bags contain 2 dark red bags.
dark red bags contain 2 dark orange bags.
dark orange bags contain 2 dark yellow bags.
dark yellow bags contain 2 dark green bags.
dark green bags contain 2 dark blue bags.
dark blue bags contain 2 dark violet bags.
dark violet bags contain no other bags.

26
2020/7/test.py Normal file
View File

@ -0,0 +1,26 @@
from prog import *
import yaml
inp_1 = parse_input(get_input(sample = True))
inp_2 = parse_input(get_input(sample = True, sample_number = 2))
result_1 = get_result(inp_1)
print(f"{result_1 = }")
print(f"{result_1 == 4}")
print()
# print(yaml.dump(inp_1))
result_2_1 = get_result(inp_1, part = 2)
print(f"{result_2_1 = }")
print(f"{result_2_1 == 32}")
print()
# print(yaml.dump(inp_2))
result_2_2 = get_result(inp_2, part = 2)
print(f"{result_2_2 = }")
print(f"{result_2_2 == 126}")
print()

Binary file not shown.

654
2020/8/input Normal file
View File

@ -0,0 +1,654 @@
acc +45
nop +631
acc +12
acc -10
jmp +127
acc +28
jmp +460
jmp +619
acc +15
jmp +277
nop +83
acc +40
acc +34
acc +15
jmp +108
acc +10
nop +61
jmp +485
jmp +44
acc +3
jmp +460
acc +46
acc +32
jmp +12
acc -1
jmp +213
acc +40
acc +4
nop +97
acc +18
jmp +613
acc +15
acc +14
nop +374
jmp +487
jmp +1
acc -1
acc +32
jmp +1
jmp +418
acc +10
acc -9
jmp +1
jmp +117
acc -5
nop +539
nop +456
jmp +191
acc +16
jmp +431
jmp +341
acc -17
acc +22
acc +33
acc +15
jmp +152
nop +277
jmp +394
acc -13
acc +49
acc -19
jmp -26
acc -5
acc +13
jmp +49
acc +37
acc +49
nop +420
acc +38
jmp +515
nop +168
acc +22
nop +151
acc +25
jmp +504
acc -16
jmp +73
acc -6
acc +40
acc +9
jmp +143
acc +40
acc -6
acc +31
nop +530
jmp +265
acc -13
acc +40
jmp +312
acc +36
jmp -55
jmp +430
jmp +551
acc +10
acc +18
nop -25
jmp +178
acc +22
jmp +176
jmp +462
acc +22
acc +23
acc +3
acc +0
jmp +162
acc +0
acc +27
jmp +100
nop +234
acc +3
nop +70
nop +112
jmp -62
acc +8
jmp +214
jmp -38
acc -15
acc +48
jmp +289
nop +6
nop +523
jmp +286
nop -9
jmp +234
jmp -74
acc +33
acc +14
nop -11
jmp -37
acc +30
jmp +277
acc +35
acc +4
jmp +96
acc +26
nop +256
acc -14
jmp +389
acc -19
acc -12
jmp +397
jmp +477
nop +141
acc +21
acc +16
nop +29
jmp +407
acc +48
jmp +243
acc +43
acc +41
nop +384
acc +24
jmp +180
jmp +372
jmp +44
acc +4
nop +234
acc +49
jmp +343
acc +0
jmp -91
acc -8
acc +26
jmp -9
acc +37
nop +321
jmp +143
jmp +278
jmp -38
acc +46
nop +67
acc +32
jmp +445
nop +143
acc +35
acc -19
acc +33
jmp +39
jmp -24
nop +393
acc +0
acc +36
acc +44
jmp -134
acc +31
acc +37
acc +5
acc -1
jmp +291
acc +37
acc +36
acc -3
jmp -183
acc -10
acc +29
acc +7
acc +32
jmp +205
acc +38
acc +20
jmp +45
acc +26
acc +0
acc +17
acc +37
jmp +289
acc +20
acc +6
acc +18
jmp -50
acc +41
acc +50
jmp +419
acc +20
jmp +333
jmp +250
acc +35
acc +13
jmp -175
acc -4
nop +179
jmp -57
jmp +243
acc -6
acc +23
nop -149
jmp +1
jmp -97
acc -14
acc +26
acc +5
nop +6
jmp -223
acc +12
nop +115
acc +38
jmp -77
acc +1
acc +25
acc +0
jmp +276
acc +37
acc +31
acc +7
jmp +201
acc +16
acc +39
acc +24
jmp +54
acc +45
nop -96
acc +17
acc -7
jmp +339
acc +6
jmp +317
acc +12
acc -1
acc -4
acc +14
jmp +89
acc +2
acc +30
jmp +60
jmp +239
acc +25
acc -9
jmp +82
acc +45
jmp +1
nop +3
jmp +1
jmp +311
jmp +142
acc +36
nop +253
jmp +341
acc +26
acc +32
acc +30
jmp -182
jmp +184
jmp +331
acc +6
jmp -68
nop -209
acc +1
acc +48
jmp -23
acc +11
acc +30
acc +45
acc -3
jmp -238
jmp +1
acc +9
jmp +45
acc +45
jmp +1
acc +44
acc +29
jmp -73
acc -4
acc +0
acc +0
jmp +294
acc +35
acc +21
jmp +309
nop +316
acc -13
jmp +1
jmp +324
acc -14
acc +42
jmp -99
nop -103
acc +16
jmp -226
nop +317
nop +316
acc -16
jmp -192
acc +33
nop -47
jmp -305
jmp -81
nop -197
nop +249
jmp +157
nop -85
jmp -246
acc +8
acc -14
acc +20
jmp -181
acc +46
nop +164
acc +12
acc -18
jmp -199
acc +10
acc -9
acc +17
acc +15
jmp +134
acc -17
acc -3
jmp +18
acc +35
acc -14
jmp +254
acc -4
acc +41
acc +45
jmp -346
acc -18
acc +41
acc +48
acc +27
jmp -33
acc -1
acc -3
acc +11
acc -13
jmp -224
acc +22
nop -73
acc -12
acc -18
jmp +213
jmp +1
acc +39
acc +19
jmp +66
jmp +126
acc +37
acc -17
acc +17
jmp -4
acc -6
acc +18
acc +9
acc -7
jmp -195
acc +33
acc +24
acc +25
acc -19
jmp -340
acc +40
acc +10
acc +23
jmp -308
jmp +1
acc +9
jmp +1
nop +104
jmp +233
jmp -24
acc +29
jmp -367
acc -15
jmp +107
acc +12
jmp +89
nop -381
jmp +1
acc -2
nop +233
jmp +238
acc +46
acc -15
acc +47
jmp -290
nop -323
acc -9
acc -6
acc +0
jmp -315
acc +21
nop +196
acc +24
acc +18
jmp -49
acc +21
jmp +1
jmp -47
acc +49
nop -120
jmp -413
acc +30
jmp -284
acc -17
jmp -212
nop +39
nop -87
acc -18
jmp -122
jmp -90
nop +76
jmp -277
acc +34
acc +49
jmp +92
nop +168
acc -1
acc +0
jmp +26
jmp -270
jmp +1
acc +14
acc +11
jmp +41
acc -15
jmp +144
jmp +149
acc +48
jmp -260
acc +27
acc -3
jmp +105
acc +47
acc -10
jmp -316
acc -4
acc +41
acc -3
nop -289
jmp -332
nop -281
nop -379
nop +62
jmp -456
acc +34
acc +23
jmp +52
acc +7
jmp -374
acc -18
acc +45
jmp +53
acc +29
nop -407
acc +34
jmp +9
acc +49
acc -1
acc -1
jmp +1
jmp -55
acc -3
acc +5
jmp -280
jmp +1
acc -13
nop -173
jmp -131
acc +5
acc +34
jmp +105
jmp -56
jmp -485
acc -14
nop -389
acc +13
acc +27
jmp -482
nop -418
jmp -394
acc -9
jmp -435
acc -14
nop -172
acc +43
jmp -159
jmp +67
acc +9
acc +22
jmp +15
nop -405
jmp -406
jmp +1
acc -19
jmp -118
acc +49
jmp -385
jmp +90
acc -10
jmp +10
acc +8
nop -315
acc -14
jmp -167
jmp +49
jmp -49
jmp -275
acc -1
jmp -136
acc +24
acc +45
jmp -259
acc +2
nop -370
acc -18
acc +4
jmp -45
acc +9
jmp -542
nop -39
nop -16
jmp +66
acc -1
nop -59
acc +23
acc -8
jmp -91
acc +7
acc +37
jmp -400
acc +39
jmp -162
nop -346
acc +5
acc +50
jmp -115
jmp -141
acc +2
acc -18
nop -179
acc -19
jmp -306
acc -10
acc +30
jmp -115
nop -47
jmp -82
acc +9
acc -4
jmp -139
acc +18
acc +16
jmp -241
jmp +1
acc -3
acc +11
jmp -309
acc +3
acc +0
acc +40
jmp +1
jmp -369
acc +31
jmp +1
acc +35
jmp -427
acc +5
acc -2
jmp -26
acc +29
nop -121
acc +6
jmp -86
nop -294
jmp -391
acc +50
nop -96
nop -325
nop -134
jmp -355
acc +6
jmp +1
jmp -396
nop -440
jmp -89
acc +22
jmp -437
acc +41
acc +8
acc +29
jmp -603
acc -18
acc +16
acc +42
jmp -339
acc +43
acc -19
nop -168
nop -253
jmp -198
jmp -613
jmp -346
acc -4
acc +7
acc +40
jmp -294
jmp -423
acc -4
acc +48
acc +41
jmp +1
jmp -49
acc +4
acc +28
acc +9
acc +38
jmp -522
jmp -5
acc +3
acc +6
acc -8
acc +44
jmp +1

62
2020/8/prog.py Normal file
View File

@ -0,0 +1,62 @@
def get_input(sample = False):
with open("sample" if sample else "input", "r") as f:
return [line.strip() for line in f.readlines()]
def parse_instruction(instruction: str):
return instruction[:3], int(instruction[4:])
def cmd_n_to_instruction(cmd, n):
return str(cmd) + " " + (f"+{n}" if n >= 0 else f"{n}")
def instruction_results(cmd, n, i, acc):
if cmd == "nop":
return i + 1, acc
elif cmd == "jmp":
return i + n, acc
elif cmd == "acc":
return i + 1, acc + n
def get_result(instructions: list, part = 1):
acc = 0
i = 0
if part == 1:
visited = set()
while i not in visited:
visited.add(i)
i, acc = instruction_results(*parse_instruction(instructions[i]), i, acc)
else:
history = []
revert = False
switched_indices = set()
while i < len(instructions):
cmd, n = parse_instruction(instructions[i])
if i in history:
revert = True
if not revert:
history.append(i)
i += n if cmd == "jmp" else 1
else:
if cmd in ["jmp", "nop"] and i not in switched_indices:
instructions[i] = cmd_n_to_instruction("jmp" if cmd == "nop" else "nop", n)
switched_indices.add(i)
revert = False
else:
i = history[-1]
history = history[:-1]
for i in history:
cmd, n = parse_instruction(instructions[i])
if cmd == "acc":
acc += n
return acc
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

9
2020/8/sample Normal file
View File

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

13
2020/8/test.py Normal file
View File

@ -0,0 +1,13 @@
from prog import *
inp = get_input(sample = True)
result_1 = get_result(inp)
expected_1 = 5
print(f"{result_1 = } {result_1 == expected_1}")
result_2 = get_result(inp, part = 2)
expected_2 = 8
print(f"{result_2 = } {result_2 == expected_2}")

Binary file not shown.

1000
2020/9/input Normal file

File diff suppressed because it is too large Load Diff

58
2020/9/prog.py Normal file
View File

@ -0,0 +1,58 @@
import yaml
def get_input(sample = False):
with open('sample' if sample else 'input', 'r') as f:
return [int(line) for line in f.readlines()]
def get_preamble(data: list, size: int):
preamble = {}
for i in range(size):
x = data[i]
for j in range(i + 1, size):
y = data[j]
preamble[(x, y)] = x + y
return preamble
def print_preamble(dic: dict):
for keys, value in dic.items():
print(f"{keys}: {value}")
def get_result(data: list, part = 1, sample = False):
if part == 1:
pre_size = 5 if sample else 25
preamble = get_preamble(data, pre_size)
for i in range(pre_size, len(data)):
elem = data[i]
if elem not in preamble.values():
return elem
elem_to_pop = data[i - pre_size]
new_preamble = {}
for keys, value in preamble.items():
if elem_to_pop not in keys:
new_preamble[keys] = value
preamble = new_preamble
for p in range(i - pre_size + 1, i):
elem_p = data[p]
preamble[(elem, elem_p)] = elem_p + elem
else:
objective = get_result(data, part = 1, sample = sample)
for length in range(2, len(data)):
for i in range(len(data) - length):
tmp = data[i:i+length]
if sum(tmp) == objective:
return min(tmp) + max(tmp)
if __name__ == "__main__":
print(get_result(get_input(), part = 2))

20
2020/9/sample 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

15
2020/9/test.py Normal file
View File

@ -0,0 +1,15 @@
from prog import *
inp = get_input(sample = True)
size = 5
result_1 = get_result(inp, sample = True)
expected_1 = 127
print(f"{result_1 = } {result_1 == expected_1}")
result_2 = get_result(inp, part = 2, sample = True)
expected_2 = 62
print(f"{result_2 = } {result_2 == expected_2}")