Compare commits

..

10 Commits

Author SHA1 Message Date
930119ce7e wip 2020-12-24 16:03:22 +01:00
5d8d3ff7dc [wip] day 16 2020-12-18 16:44:29 +01:00
73d972fbea [wip] day 11 2020-12-15 23:20:30 +01:00
2cad32dda7 day15 challenge 2020-12-15 18:17:17 +01:00
50e0fb7141 day 14 challenge 2020-12-15 17:02:18 +01:00
f74713233a day 10 challenge 2020-12-10 22:40:04 +01:00
f20fc27a1c day9 challenge 2020-12-09 09:20:16 +01:00
1cbe411264 day 8 challenge 2020-12-08 09:24:46 +01:00
181029fcdc day 7 challenge 2020-12-07 17:25:02 +01:00
9c619282f4 day 3: another method 2020-12-06 15:59:57 +01:00
21 changed files with 3842 additions and 24 deletions

24
day10/day10.py Normal file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
from collections import Counter
def part1(adapters):
counts = Counter()
# 1 for the socket, of 3 for the device
for current, next in zip([0] + adapters, adapters + [3]):
counts[next - current] += 1
return counts[1] * counts[3]
def part2(adapters):
counts = Counter({0: 1})
for jolt in adapters:
s = counts[jolt - 1] + counts[jolt - 2] + counts[jolt - 3]
counts[jolt] = s
return max(counts.values())
if __name__ == "__main__":
adapters = sorted(int(l.rstrip()) for l in open("input.txt"))
print(part1(adapters))
print(part2(adapters))

99
day10/input.txt Normal file
View File

@ -0,0 +1,99 @@
151
94
14
118
25
143
33
23
80
95
87
44
150
39
148
51
138
121
70
69
90
155
144
40
77
8
97
45
152
58
65
63
128
101
31
112
140
86
30
55
104
135
115
16
26
60
96
85
84
48
4
131
54
52
139
76
91
46
15
17
37
156
134
98
83
111
72
34
7
108
149
116
32
110
47
157
75
13
10
145
1
127
41
53
2
3
117
71
109
105
64
27
38
59
24
20
124
9
66

32
day11/day11.py Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python3
from rules import part1_rules
def main(grid, rules):
generation = 0
while True:
changes, next_grid = step(grid, rules)
generation += 1
grid = next_grid
assert generation < 1000
if changes == 0:
return next_grid.count("#")
def step(grid, rules):
changes = 0
next_grid = grid[:]
for index, cell in enumerate(grid):
try:
changes += rules[cell](index, grid, next_grid)
except KeyError:
pass
return changes, next_grid
if __name__ == "__main__":
with open("input.txt") as infile:
grid = list("".join(infile.read().splitlines()))
print("Part 1 ", main(grid, rules=part1_rules))
# print("Part 2 ", main(grid, rules={"L": handle_empty_2, "#": handle_occupied_2}))

28
day11/grid.py Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env python3
class Grid:
def __init__(self, inp):
lines = inp.read().splitlines()
self.cells = list("".join(lines))
self.height = len(lines)
self.width = len(lines[0])
def __getitem__(self, key):
x, y = key
return cells[y * self.width + x]
def __setitem__(self, key, value):
x, y = key
cells[y * self.width + x] = value
def __iter__(self):
return self.cells.__iter__()
def __str__(self):
"\n".join(
"".join(
grid[pos : pos + grid_width]
for pos in range(0, self.width, self.height)
)
)

97
day11/input.txt Normal file
View File

@ -0,0 +1,97 @@
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLL..LLLLLLLLLLLL.LLL..LLLLLLLLLLLLLL.LL.LLLLL.LLLLLLLLL.LLLLLLLLLLLLL
LLLLLLL.LLLLLLL.LLLLLLLLL.LLLLL.LLLL.LLLLLLLL.LLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLLLL..LLLLLLL..LLLL
LLLLLL.LLLLLLLLLLLLLLLLLL.LLLLL.LLLLLLLLL.LLL.LLLLLLLLLLLLLL.LLLLLLL..LLLLLLLLLLLLLLLLLLLLLL.LLLLL
LLLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLL.LLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLL..LLLLLLLLL.LLLLLLL..LLLL
.LLL.LL.LLLLLLL.LLLLLLLLL.LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL.LLLLLLL.LLLLL.LLLLLLLLL.LLLLLLLLLLLLL
LL.LLLL.LLLLLLLLLLLLLLLLL.LLLLL.LLLL.LLLLLLLLLLLLL.LLL.LLLLLLL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LL
LLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLL.LLLLLLLL.LL.LLLL.LLLLLL.LLLLLLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL
LLLL.LL.LLLLLLL.LLLLLLLLL.LLLLL.LLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLLLL.LLLLLLLLLLLLLLL.LLLLLLL.LLLLL
LLLLLLLLLLLLLLLLLLLLLLLLL.LLLLL.LL.LLLLLLLLLL.LLLL.LLLLLLLLL.LLLLLLL.LLLLL.LLLLLLL.LLLLLLLLL.LLLLL
LLLLLLL.LLLLLLL..LLLLLLLLLLLLLLLLLLL.LLLLLLLLLLLLL.LLLLLLLLL.LL.LLLL.LLLLL.LLLLLLLLL.LLLLLLL.LLLLL

115
day11/rules.py Normal file
View File

@ -0,0 +1,115 @@
#!/usr/bin/env python3
from itertools import count, takewhile
directions = (
(-1, -1),
(-1, 0),
(-1, 1),
(0, -1),
(0, 1),
(1, -1),
(1, 0),
(1, 1),
)
grid_width = 98
grid_height = 97
def handle_empty(index, grid, next_grid):
"""
If a seat is empty (L) and there are no occupied seats adjacent to it, the seat becomes occupied.
"""
neighbors = count_neighbors(index, grid)
if neighbors == 0:
next_grid[index] = "#"
return 1
return 0
def handle_occupied(index, grid, next_grid):
"""
If a seat is occupied (#) and four or more seats adjacent to it are also occupied, the seat becomes empty.
"""
neighbors = count_neighbors(index, grid)
if neighbors >= 4:
next_grid[index] = "L"
return 1
return 0
def count_neighbors(pos, grid):
neighbors = 0
x = pos % grid_width
y = pos // grid_width
for (dx, dy) in directions:
xx = x + dx
yy = y + dy
if not in_bounds((xx, yy)):
continue
if grid[yy * grid_width + xx] == "#":
neighbors += 1
return neighbors
def handle_empty_2(index, grid, next_grid):
"""
If a seat is empty and there are no occupied seat visible in neither direction,
the seat becomes occupied
"""
neighbors = 0
x = index % grid_width
y = index // grid_width
for direction in directions:
# keep moving in the specified direction, while checking
# that we are in bounds of the grid
for xx, yy in takewhile(in_bounds, move(x, y, direction)):
cell = grid[yy * grid_width + xx]
if cell == "#":
neighbors += 1
elif cell == "L":
break # No occupied seat in that direction, we can break
if neighbors == 0:
next_grid[index] = "#"
return 1
return 0
def handle_occupied_2(index, grid, next_grid):
"""
An occupied seat becomes empty if there are five or more visible occupied
seats in either direction.
"""
occupied = 0
x = index % grid_width
y = index // grid_width
for direction in directions:
for xx, yy in takewhile(in_bounds, move(x, y, direction)):
print(xx, yy)
cell = grid[yy * grid_width + xx]
if cell == "#":
occupied += 1
if occupied >= 5:
next_grid[index] = "L"
return 1
return 0
def in_bounds(pos):
x, y = pos
return 0 <= x < grid_width and 0 <= y < grid_height
def move(x, y, direction):
pos = x, y
while True:
yield pos
pos = x + direction[0], y + direction[1]
part1_rules = {"L": handle_empty, "#": handle_occupied}
part2_rules = {"L": handle_empty_2, "#": handle_occupied_2}

58
day14/day14.py Normal file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env python3
from collections import defaultdict
def part1(infile):
memory = defaultdict(int)
for line in infile:
left, right = line.split("=")
if left.startswith("mask"):
one_mask = right.translate(right.maketrans("X", "0"))
zero_mask = right.translate(right.maketrans("X10", "001"))
else:
address = int(left.split("[")[1].rstrip("] ")) # mem[42] -> 42
value = int(right.rstrip())
memory[address] = value & ~int(zero_mask, 2) | int(one_mask, 2)
return sum(memory.values())
def part2(infile):
memory = defaultdict(int)
for line in infile:
left, right = line.split(" = ")
if left.startswith("mask"):
mask = right.rstrip()
else:
value = right.rstrip()
address = apply_mask(left.split("[")[1].rstrip("] "), mask)
for addr in generate_floating_addresses(address):
memory[int(addr, 2)] = int(value)
return sum(memory.values())
def apply_mask(address, mask):
address = bin(int(address)).lstrip("0b")
address = address.zfill(36)
for index, bit in enumerate(mask):
if bit == "1":
address = address[:index] + "1" + address[index + 1 :]
elif bit == "X":
address = address[:index] + "X" + address[index + 1 :]
return address
def generate_floating_addresses(address):
index = address.find("X")
if index == -1:
return [address]
a1 = generate_floating_addresses(address[:index] + "0" + address[index + 1 :])
a2 = generate_floating_addresses(address[:index] + "1" + address[index + 1 :])
return a1 + a2
if __name__ == "__main__":
with open("input.txt") as infile:
print(part1(infile))
infile.seek(0)
print(part2(infile))

564
day14/input.txt Normal file
View File

@ -0,0 +1,564 @@
mask = 1000XX0X0X0X0011XX11110110X101101X01
mem[17353] = 91550
mem[3346] = 113780395
mem[25928] = 15887
mask = 1100X110000111X1X010X101X01110110X01
mem[22673] = 365674634
mem[56387] = 707
mem[59272] = 66101
mask = 00110000X1011011111X1X100X1001111000
mem[26721] = 1906961
mem[6434] = 1547
mem[38772] = 3670902
mask = 1X0110X001101011X011000011000010X100
mem[14129] = 9885418
mem[16579] = 19578559
mem[17948] = 222711
mem[39312] = 3696
mem[28037] = 4392
mask = 1XX01010010100101010X10X0X100X110X0X
mem[27174] = 34330
mem[38975] = 1673
mem[53860] = 43706522
mem[24314] = 129
mem[46690] = 2122756
mem[51409] = 300
mask = X0X00100X110101XX1110000001000X01101
mem[16769] = 6839
mem[4773] = 197670
mem[16306] = 9387
mem[23109] = 18936748
mask = X001X00001111X11X11XX1000001001X1111
mem[9277] = 2126
mem[19599] = 2620
mem[35796] = 1119795
mem[43013] = 7907629
mem[34780] = 73089
mem[43625] = 1251
mem[45268] = 35981183
mask = 11X0XX100X01001010101000X000X00X0001
mem[28057] = 87060
mem[57943] = 156869
mem[34328] = 441008
mem[19172] = 974642
mem[13455] = 140868162
mem[10479] = 1478
mem[3348] = 610
mask = 1X0011X0000X00X111111X0011001100XX00
mem[20706] = 371595403
mem[32191] = 61238
mem[32541] = 121
mask = 000101X1X110X01X1010X1XX011XX0110110
mem[2502] = 3004
mem[42813] = 50475
mem[6736] = 218863
mem[57229] = 542
mask = X00011110X101011X01100X11011010X100X
mem[29838] = 6609
mem[63501] = 76
mem[35757] = 447
mem[19646] = 1841
mem[50155] = 10989663
mask = 10011000X01110XX1111X10XX00000101001
mem[16439] = 1250783
mem[50267] = 12877
mask = 000X0X011110101X101X010X1X1100X0X1X1
mem[55873] = 29485206
mem[3857] = 932873
mem[53144] = 49937201
mem[45634] = 3973
mem[62141] = 84958
mask = 10001X110XX01011X1100X011010110110XX
mem[27094] = 64589302
mem[20130] = 1670
mem[42036] = 39179827
mem[31787] = 25295623
mem[39027] = 1380
mem[53488] = 593805
mem[27469] = 6270971
mask = 0101000001111011101110XXX010X0100010
mem[34667] = 1338
mem[2529] = 49045
mem[40550] = 149
mem[56292] = 14155
mask = 1100111X0X0110X11111111010X001001111
mem[6465] = 8116
mem[45171] = 158525709
mem[10613] = 1661122
mem[37037] = 19153
mask = 1X0000X1111X1010X1110101100001X10101
mem[3530] = 361
mem[15560] = 140278839
mem[62028] = 12515878
mem[20628] = 11032
mem[48912] = 111176
mem[47515] = 605
mask = X00111001XX11011X1111X000100X0X0X010
mem[4615] = 738
mem[672] = 1477
mem[16686] = 24069368
mask = 110011100XX10000X0X00XX0X11100X10111
mem[12619] = 1252770
mem[954] = 590503
mem[16403] = 1087106
mem[11529] = 24258
mem[11701] = 160993242
mem[42676] = 64764346
mem[7626] = 316
mask = X001100XXX111X111X1111X000X0X0011100
mem[42659] = 2822
mem[40278] = 2173727
mem[32236] = 13461
mem[8739] = 49532769
mem[23981] = 6272019
mem[26083] = 7424
mask = 1X001110010X101110111001100X0101XX01
mem[5207] = 285084
mem[46863] = 202944
mem[29623] = 74688785
mem[39251] = 2480123
mem[21934] = 128729
mem[17298] = 74932253
mem[3243] = 2421447
mask = 100001000X11100X1X110010XX1010XX010X
mem[45668] = 70363
mem[5250] = 19909279
mem[20889] = 8027
mem[61368] = 422881
mask = 1010110X0X111X1111110000X01100XX010X
mem[7264] = 4257
mem[62228] = 4486
mem[11135] = 31885819
mem[50978] = 523114
mem[12827] = 9872
mask = 10X011010110X011001X11001X1100X11101
mem[15425] = 38832030
mem[7190] = 3685311
mem[4442] = 111088
mem[46774] = 679
mem[48679] = 30399
mask = 101100X111011111X1111100X1X100001001
mem[21055] = 143042
mem[44782] = 112377326
mem[62184] = 8230
mem[49662] = 512539
mem[26324] = 73321
mem[17454] = 107773
mem[63437] = 73219244
mask = 10000111011110111X1000XX1010X1X0X111
mem[36342] = 1818
mem[18094] = 47648232
mem[52003] = 776369
mask = 11001X100XX0X01111111XX0110111X00110
mem[29103] = 5339928
mem[36458] = 988421275
mem[749] = 185734229
mem[33969] = 29427002
mask = 10X1X0X111X11XX11X11110011XX00011100
mem[18473] = 197816
mem[140] = 1537228
mem[5706] = 1016744730
mem[21968] = 425238881
mem[2299] = 7217883
mem[36197] = 66
mask = 100110X10X11X011111111X100110X110X00
mem[5148] = 3669
mem[50092] = 313576115
mem[1719] = 23750788
mem[62734] = 2882
mem[49010] = 14217157
mask = 1X0XXX00011X10111X1110000011101X0X1X
mem[24047] = 11171624
mem[34404] = 251169353
mem[23056] = 3568348
mem[2599] = 9449217
mask = 0X0X11X1011010111X101X00X111X0001100
mem[49530] = 1917
mem[23017] = 4137
mem[42892] = 209824
mem[44196] = 2282
mem[340] = 416390430
mem[40836] = 4717162
mask = 1101X000XX1010111011XX1X0000100X0000
mem[20534] = 116
mem[51190] = 846413
mem[43522] = 88862477
mem[56757] = 7097
mask = 00000101111XX01110X0X00000111000110X
mem[20975] = 25703
mem[11316] = 7721
mem[56239] = 29785
mem[51862] = 145224773
mem[3358] = 10907
mem[13070] = 77929
mask = 0X0011110110X0111X1XX11001100X0X11XX
mem[22991] = 231
mem[33217] = 2826
mem[34404] = 509
mask = 100X11X00000X0X11111000XX000X01010X0
mem[18012] = 4386
mem[56514] = 16103818
mem[46863] = 7016934
mem[53389] = 2025015
mem[5646] = 77832170
mask = 110011X00001X0X11111X100X0000100X01X
mem[38058] = 327471
mem[7489] = 247743521
mem[41341] = 980157
mask = 10X01XX000X1001X1111X000X101000111X1
mem[2278] = 1003775
mem[4957] = 695497071
mem[27026] = 83380
mem[58747] = 3055795
mem[35663] = 424302
mem[55675] = 1400
mem[59995] = 15450
mask = 0X011001001X1X1X10110100011011001011
mem[18012] = 105413272
mem[18353] = 2478
mem[10658] = 33943560
mem[64129] = 97108
mem[16290] = 585316720
mem[38816] = 26080808
mask = 100X1X10XXX0101X101X000X00111011011X
mem[37923] = 340333740
mem[34920] = 429908705
mem[955] = 1727757
mem[65269] = 221055157
mem[10891] = 523742
mem[7264] = 21158973
mask = 10XX1100011X10111X1100X00000X0111111
mem[61904] = 63495
mem[57943] = 33076
mem[20097] = 836033572
mem[12549] = 55029
mem[3024] = 3602462
mask = 110X0000011010X11011X0X0101X10XX000X
mem[14134] = 1542
mem[802] = 10323
mem[51543] = 171365721
mem[12827] = 3980
mask = 1000X100011110X1111100X100XXX0X001X1
mem[8136] = 449831
mem[1281] = 999072275
mem[20796] = 332579
mem[443] = 131455
mem[12894] = 18123
mem[50922] = 5177801
mask = 100XXX0001101011X1110X000001101011XX
mem[18244] = 930
mem[672] = 89370
mem[42478] = 50196
mem[35527] = 16
mem[61716] = 105683782
mask = 1000XX00011010111X110X0X1011101XX110
mem[6775] = 3861120
mem[843] = 312
mem[2688] = 196099
mem[37141] = 377569
mem[33497] = 825
mem[32589] = 1629649
mask = 10X100011X1X1011X01110XX11X01100X100
mem[20624] = 315487
mem[31408] = 72488
mem[63467] = 13483
mem[2471] = 177211433
mem[45598] = 62138
mem[25301] = 6365509
mask = 110011X0000111001X110110X00XX00001X0
mem[42036] = 7869
mem[55966] = 14443044
mem[27440] = 100934729
mem[19003] = 2085
mem[15653] = 2142716
mem[23117] = 1021
mem[45011] = 5295150
mask = X100101X0000X01111111001110X010X111X
mem[57308] = 11803
mem[2240] = 961172
mask = 100011X0011010111X1XX100101010XXX1X0
mem[2444] = 243334769
mem[12549] = 40175975
mask = X0011001X011111110110XX00X0X00X11011
mem[24834] = 363054
mem[32941] = 83666205
mem[16403] = 444996
mask = 1100X1100001XXXX101X01001X101000010X
mem[56757] = 6879
mem[4442] = 2107238
mem[25399] = 14684
mem[38582] = 330023
mem[59557] = 299
mem[34404] = 357591660
mask = 0100X11101100011111XX1X000100011111X
mem[19990] = 405059382
mem[50770] = 21723749
mem[47204] = 310
mem[55142] = 353841
mem[31516] = 46662
mem[59748] = 154981
mask = 100X111001X010111X110X1X101110X01111
mem[25989] = 412990662
mem[44019] = 11063
mem[5207] = 25633
mem[23445] = 2402831
mem[30252] = 60933
mask = 100X111001001X10X0100XXX0011011X10X0
mem[45485] = 5697187
mem[39779] = 21767171
mem[34966] = 498
mem[13640] = 123685
mask = X001X00X0XX11X1111111001X111X11111X0
mem[30646] = 77071
mem[40278] = 15164
mem[48949] = 2547
mem[49010] = 168697055
mem[52212] = 836232
mask = X00011000111101111X100X100100X00XX1X
mem[13958] = 872
mem[28057] = 130528
mem[9891] = 1464
mask = 00X10000000X11111111X0100X1X0X111111
mem[29510] = 29331
mem[16403] = 265384902
mem[46270] = 55500
mem[35558] = 149875
mem[42316] = 8508705
mem[12894] = 281336
mask = 10X011XX01X00011001110X11111X00X1XX0
mem[15463] = 114059
mem[64253] = 5760
mem[34294] = 38569
mem[1677] = 5097
mem[22991] = 502
mem[44522] = 326097
mem[8172] = 37
mask = 00010000X0001X1111111011011101X1X110
mem[39779] = 1142
mem[29838] = 85552455
mem[42813] = 5712091
mem[45115] = 58778
mem[13319] = 855
mem[2440] = 410159
mask = X101101101X01111101010X110X110000010
mem[41886] = 1753
mem[57501] = 961519277
mem[48943] = 1352369
mask = 1000011X01111X1111101XX0000X101XX110
mem[840] = 954719
mem[53875] = 11370
mem[45011] = 5033013
mem[45230] = 850083
mem[20455] = 862
mask = 1X00010XX111101X111110000X111011X1X0
mem[34148] = 99301330
mem[26648] = 7719906
mem[18244] = 110630512
mask = 1100X11000X11X0X1111100X0X00X010XX11
mem[50401] = 1733252
mem[26875] = 37568501
mem[35663] = 508001
mem[14749] = 1838
mask = X1010XX001111011101X0000X001XX100010
mem[63359] = 5414799
mem[35329] = 251023948
mem[26907] = 876247525
mask = X000X0X1111XX0100111XX10101X011X1100
mem[23165] = 20505666
mem[7340] = 1068126
mem[5630] = 2429
mem[55672] = 30150
mask = 1000X11X011X101111101X0XX0101X1010X0
mem[19212] = 6837122
mem[14758] = 38425
mem[19003] = 119768
mask = 10000X01111110X0X1111110XXX110011X10
mem[33194] = 61265858
mem[13147] = 3274970
mem[41650] = 4162
mem[42478] = 1225726
mem[63031] = 112464577
mask = X0X10000X101101111110011X11101111100
mem[35647] = 5788908
mem[42040] = 48997
mem[62673] = 1901
mem[39850] = 1010636
mask = 11X010X0010100101X1XXX0001001111010X
mem[20116] = 50
mem[57943] = 17495168
mem[28763] = 19897421
mem[21657] = 923815
mem[4802] = 86976237
mask = 1X0011X001100011XX1X100X101110100110
mem[13898] = 4734170
mem[1595] = 82201
mask = 1001X0010011X111111X1X0X1X1100011000
mem[44782] = 14922
mem[54309] = 1336
mem[23027] = 194803
mem[24035] = 29316023
mask = 1100111000010101X011X00011100X00010X
mem[50916] = 1751
mem[47305] = 2707
mem[14464] = 13519228
mem[33044] = 10744
mem[53730] = 4920479
mem[37037] = 859
mask = X100111X0X10001111111100X11110001110
mem[58049] = 939221
mem[1924] = 17
mem[61135] = 358315072
mem[21809] = 5281
mem[39141] = 1817
mem[51543] = 136115569
mem[50155] = 300797
mask = 110010X000X1110010X100X0111X001X00XX
mem[50279] = 14014916
mem[12124] = 68328623
mem[44199] = 313076
mem[64321] = 4725
mem[20842] = 108600115
mem[37411] = 4492927
mask = X1001X11000010111111XX0X100X11000011
mem[28505] = 8712
mem[37967] = 35824634
mem[23027] = 241
mem[17252] = 20614619
mem[24389] = 10076
mask = X101000001X01011X011X0X10X1100101X10
mem[61716] = 8801
mem[34944] = 1881
mem[4710] = 8504
mem[56313] = 14501
mem[5654] = 14055781
mem[22490] = 90967
mask = X0X1110X01101011111101001100001X1101
mem[21158] = 463323
mem[18946] = 15357
mem[57000] = 2534149
mem[15029] = 194259123
mem[38305] = 441356
mask = 11001110010X000X101000XX010000111111
mem[53389] = 1383160
mem[938] = 1952336
mem[64009] = 15833
mask = 00X11X0011X11011111111000X10001X11X1
mem[6272] = 13767595
mem[54734] = 510
mem[33438] = 1925
mem[36878] = 260095
mask = 110X11100111X0001X000001011001X01011
mem[47847] = 2621
mem[49530] = 526
mem[17284] = 1326861
mem[17082] = 5186894
mem[18302] = 13617528
mem[7269] = 1111687
mask = 110011100001X11X101X1X101010X01X0100
mem[60461] = 2942
mem[35460] = 327
mem[28055] = 375226
mask = 0011111X01101111111010XXX101X101100X
mem[41886] = 113214
mem[17284] = 85512736
mask = 0X01X111X1101X1110100101011110011XX1
mem[40617] = 603263
mem[10573] = 33216107
mem[22356] = 26505
mem[6272] = 45384662
mask = 10101X0001111011X11X000111X1X1100X0X
mem[7936] = 47932
mem[16185] = 5024
mem[52003] = 1045816
mask = 0XXX1X1101101X111X1001X000110001110X
mem[32145] = 91132
mem[55966] = 3856425
mem[42185] = 24094
mem[36708] = 277
mask = 1101100XX11X1011111110X0100X10X0000X
mem[31516] = 5220059
mem[35747] = 2317
mem[7864] = 3365
mem[55570] = 45702
mask = 110110010X1110X1X111000X0000101X1X00
mem[44696] = 47285061
mem[28866] = 23561
mem[56107] = 8116244
mem[41437] = 2106148
mask = 110011X00011001111XX100X11001010010X
mem[45954] = 58871
mem[61135] = 3411
mem[17541] = 3200218
mem[38985] = 233678515
mem[41259] = 166543015
mem[2350] = 34876506
mask = 11X01X00X0X00001111XX00101X0X0100010
mem[23027] = 474324
mem[6434] = 53973
mem[40128] = 16133
mem[36404] = 5183
mask = 1100111000XX00111X11110X11X00X10000X
mem[10063] = 9539320
mem[843] = 671
mem[4773] = 140929
mem[19139] = 133212046
mem[20975] = 795877
mask = 100X0X00011X101111X101000010X0001000
mem[932] = 2504742
mem[25530] = 1425628
mask = 10X001X00X1X1X011X1100110X1X1011X000
mem[8358] = 313827173
mem[7256] = 1152512
mem[6697] = 60311
mem[15728] = 6743
mem[64009] = 43785
mem[43325] = 2846
mask = 100X1X00011X1011111X000000X0X01X1X00
mem[46292] = 1644
mem[1988] = 1949
mem[40476] = 111556
mask = 100011X0X11XX01110111X001001X010111X
mem[43625] = 120590
mem[63878] = 417
mem[1924] = 4511945
mem[36404] = 2609999
mem[8758] = 30953
mem[896] = 56891660
mem[37141] = 770
mask = 100011X001X0X0111X11100000XXX0010X10
mem[19084] = 9020
mem[39875] = 31650099
mask = 10101110011000110011XX11X110011X1010
mem[13319] = 1038
mem[46337] = 51363384
mem[61871] = 3928
mem[15595] = 224135
mem[56790] = 39964747
mem[54731] = 1878594
mem[53872] = 4678318
mask = 00X11001001110111011X0X001X111110X11
mem[39549] = 14142886
mem[26096] = 7903442
mem[43322] = 8676
mem[17353] = 509961
mem[49320] = 11303
mask = 1X0100000X00X011X01X011000X0X0111000
mem[48878] = 209296
mem[29990] = 394600
mask = 100000000X10101X11110XX0101011000011
mem[843] = 542527866
mem[63601] = 10350671
mem[9659] = 3514
mem[33969] = 266
mem[2863] = 15309
mask = 10X0X000011X10XX01100101100XX01X0010
mem[56350] = 2980026
mem[45422] = 7205
mem[26310] = 10221
mem[40386] = 358165
mem[55012] = 32294336
mask = X1001X10000111001011X1001011X0010110
mem[25508] = 86175837
mem[26087] = 58400593
mem[48996] = 27712
mem[3272] = 2146

58
day15/day15.py Normal file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env python3
from collections import defaultdict
from array import array
def main(initial_suite, max_iteration):
iteration = 1
seen = defaultdict(int)
# init
for number in initial_suite:
seen[number] = iteration
iteration += 1
current = 0
while iteration < max_iteration:
last_seen = seen[current]
if last_seen == 0:
seen[current] = iteration
current = 0 # next
else:
seen[current] = iteration
current = iteration - last_seen # next
iteration += 1
return current
def main_array(initial_suite, max_iteration):
iteration = 1
seen = array('I', [0] * max_iteration)
# init
for number in initial_suite:
seen[number] = iteration
iteration += 1
current = 0
while iteration < max_iteration:
last_seen = seen[current]
if last_seen == 0:
seen[current] = iteration
current = 0 # next
else:
seen[current] = iteration
current = iteration - last_seen # next
iteration += 1
return current
if __name__ == "__main__":
inp = [6, 3, 15, 13, 1, 0]
# 423 µs ± 53.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
print(main(inp, 2020))
# 13.6 s ± 2.89 s per loop (mean ± std. dev. of 7 runs, 1 loop each)
#print(main(inp, 30000000))
print(main_array(inp, 30000000))

16
day16/bash.exe.stackdump Normal file
View File

@ -0,0 +1,16 @@
Stack trace:
Frame Function Args
00600000010 001800617BE (00180251890, 0018023DFD1, 00000000058, 000FFFFB770)
00600000010 001800490FA (00000000000, 00100000000, 00000000000, 00000000001)
00600000010 00180049132 (00000000000, 00000000000, 00000000058, 0018031F2C0)
00600000010 0018006D9C9 (0000000000A, 000FFFFC940, 001800458BF, 00000000000)
00600000010 0018006DB92 (00000000003, 000FFFFC940, 001800458BF, 000FFFFC940)
00600000010 0018006EA4C (000FFFFC940, 001802405E5, 001800EAF57, 0000000000D)
00600000010 001800596A6 (000FFFF0000, 00000000000, 00000000000, 773CE092FFFFFFFF)
00600000010 0018005A9C5 (00000000002, 0018031EBD0, 001800BE5F9, 00600040000)
00600000010 0018005AE89 (001800C7664, 00000000000, 00000000000, 00000000000)
000FFFFCCE0 0018005B149 (000FFFFCE00, 00000000000, 00000000030, 0000000002F)
000FFFFCCE0 00180049877 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0 001800482C6 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0 00180048374 (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace

105
day16/day16.py Normal file
View File

@ -0,0 +1,105 @@
# /usr/bin/env python3
import re
from collections import defaultdict
"""
identify invalid nearby tickets by considering only whether tickets contain values that are not valid for any field.
"""
def main():
rules, my_ticket, other_tickets = open("input.txt").read().split("\n\n")
rules = parse_fields(rules)
my_ticket = my_ticket.splitlines()[1]
other_tickets = other_tickets.splitlines()[1:]
print("Ticket scanning error rate ", part1(other_tickets, rules))
part2(my_ticket, other_tickets, rules)
def parse_fields(fields):
fields_dict = {}
for field in fields.splitlines():
k, v = field.split(": ")
ranges = re.findall(r"(\d+)-(\d+)", v)
fields_dict[k] = [range(int(r[0]), int(r[1]) + 1) for r in ranges]
return fields_dict
def part1(tickets, rules):
scanning_error_rate = 0
for ticket in tickets:
scanning_error_rate += sum(validate_ticket(ticket, rules))
return scanning_error_rate
def validate_ticket(ticket, rules):
invalid_fields = []
for value in ticket.split(","):
value = int(value)
if not validate_field(value, *rules.values()):
invalid_fields.append(value)
return invalid_fields
def validate_field(field, *rules):
validations = (any(field in r for r in rule) for rule in rules)
return any(validations)
def part2(my_ticket, other_tickets, rules):
# filter only valid tickets
valid_tickets = [ticket for ticket in other_tickets if validate_ticket(ticket, rules) == []]
valid_tickets.append(my_ticket) # my ticket is valid
# possible field for each index of a ticket
candidates = defaultdict(set)
for index in range(len(rules)):
def inner():
for rule_name, constraints in rules.items():
for ticket in valid_tickets:
field_value = int(ticket.split(",")[index])
if not validate_field(field_value, constraints):
return
candidates[index].add(rule_name)
inner()
sorted_candidates = sort_candidates(candidates)
fields_indexes = {}
try:
while len(fields_indexes) != len(rules):
index, found = sorted_candidates.popitem()
found = next(iter(found))
fields_indexes[index] = found
sorted_candidates = remove_item(sorted_candidates, found)
except:
pass
fields_indexes = {k: v for k,v in fields_indexes.items() if v.startswith('departure')}
total = 1
my_ticket = my_ticket.split(',')
for index in fields_indexes:
total *= int(my_ticket[index])
a = 1
def sort_candidates(c):
return {x: c[x] for x in sorted(c, key=lambda k: len(c[k]), reverse=True)}
def remove_item(candidates, item):
ret = {}
for key, value in candidates.items():
try:
value.remove(item)
except ValueError:
pass
ret[key] = value
#candidates = {k: set(v - item) for k,v in candidates.items()}
return ret
if __name__ == "__main__":
main()

260
day16/input.txt Normal file
View File

@ -0,0 +1,260 @@
departure location: 32-69 or 86-968
departure station: 27-290 or 301-952
departure platform: 47-330 or 347-956
departure track: 46-804 or 826-956
departure date: 25-302 or 320-959
departure time: 29-885 or 893-961
arrival location: 33-643 or 649-963
arrival station: 29-135 or 151-973
arrival platform: 50-648 or 674-961
arrival track: 45-761 or 767-971
class: 46-703 or 725-951
duration: 47-244 or 257-957
price: 49-195 or 209-956
route: 44-368 or 393-968
row: 48-778 or 797-954
seat: 31-421 or 427-964
train: 42-229 or 245-961
type: 31-261 or 281-964
wagon: 36-428 or 445-967
zone: 30-906 or 923-960
your ticket:
157,89,103,59,101,181,109,127,67,173,151,97,107,167,61,131,53,163,179,113
nearby tickets:
463,746,834,524,530,944,558,680,416,986,364,677,850,160,641,99,898,360,860,695
131,550,365,282,759,549,212,841,933,177,109,407,859,5,560,119,929,178,725,769
216,726,353,875,585,448,513,866,55,266,696,173,367,684,99,624,561,735,880,347
775,949,284,404,832,445,4,368,702,492,577,133,930,170,212,642,213,881,616,67
948,608,525,771,739,732,556,615,843,447,254,605,573,838,399,104,285,568,59,112
491,225,446,229,585,462,159,898,365,811,538,469,223,364,943,931,860,835,607,864
414,164,269,604,564,592,608,179,593,397,326,740,774,445,525,215,354,518,446,776
880,224,616,325,182,619,635,875,580,78,499,699,225,158,408,119,400,555,514,591
404,53,154,419,698,67,126,607,519,576,411,51,636,554,856,900,571,133,136,774
758,87,214,54,193,99,400,544,452,63,481,559,488,897,867,463,426,946,284,189
489,447,687,643,851,104,172,528,551,694,685,101,772,172,575,100,838,927,992,881
287,871,570,537,130,290,492,510,163,477,751,273,802,854,624,228,530,591,640,801
406,830,574,569,627,886,547,850,897,773,362,687,398,359,102,179,904,480,121,553
110,879,900,570,508,612,944,408,160,505,767,702,645,65,753,588,463,871,403,359
454,210,123,894,882,285,112,625,936,135,944,88,153,509,852,124,861,997,620,348
185,302,106,452,607,408,111,875,204,861,769,545,499,460,541,895,329,756,329,929
510,24,65,939,885,469,175,587,837,516,478,593,321,696,734,525,107,227,459,694
449,461,195,330,768,501,308,869,747,837,935,109,125,212,212,410,405,358,323,740
324,834,284,411,181,668,548,904,900,105,112,413,687,499,281,323,624,175,214,595
222,110,150,626,488,688,185,593,738,409,619,419,351,87,836,172,474,613,539,641
102,107,614,445,524,414,550,527,556,132,64,767,586,830,226,638,60,900,197,895
173,508,122,768,479,624,554,177,496,726,536,853,607,640,167,845,415,536,248,859
507,617,67,881,585,97,132,769,484,245,799,301,101,405,682,936,578,680,87,756
491,847,160,221,94,832,889,120,576,120,124,756,847,113,169,155,688,217,400,573
744,524,90,867,548,906,895,867,58,682,326,733,354,168,199,753,729,770,447,480
282,89,694,575,738,862,879,131,542,539,590,605,697,675,631,301,834,571,765,325
553,414,732,155,924,108,123,592,321,558,646,624,688,456,51,729,185,193,420,564
259,454,89,579,475,240,290,90,883,740,88,615,856,348,474,101,486,539,98,413
620,347,175,930,604,755,662,733,867,157,458,58,367,609,926,545,219,69,545,593
58,121,126,826,263,218,219,456,691,536,66,193,701,354,564,866,676,182,804,948
159,860,447,828,361,162,523,544,641,629,869,477,894,102,751,799,396,395,650,846
200,65,905,393,856,56,874,906,949,412,741,570,56,479,600,541,578,348,734,365
694,830,665,745,694,590,590,640,111,611,639,770,566,551,258,531,901,585,736,504
626,219,100,934,573,583,847,949,562,847,739,672,559,585,638,527,771,826,947,131
471,608,301,588,109,586,209,537,835,136,559,156,829,87,526,610,494,862,580,117
319,158,288,158,897,100,453,166,194,327,609,756,58,412,213,133,628,518,942,59
452,468,575,778,577,854,604,59,899,943,697,827,715,609,565,464,576,588,542,483
676,827,772,460,875,415,587,218,660,577,612,731,697,122,94,502,101,301,195,210
635,829,732,558,114,804,626,503,408,13,501,882,454,452,108,938,471,834,502,617
283,53,517,497,628,552,884,194,560,938,552,833,531,278,218,896,618,878,837,118
76,493,861,123,110,117,680,50,515,776,842,567,549,777,803,459,517,52,563,257
887,861,214,872,487,582,641,741,636,186,364,563,552,633,630,350,151,902,172,165
161,478,353,777,361,596,501,879,642,420,456,907,634,826,852,840,505,923,895,192
905,510,756,415,772,533,153,799,407,571,171,425,117,229,610,631,187,65,850,774
223,676,134,129,261,211,175,191,411,224,304,544,777,864,53,61,51,900,529,637
272,747,598,799,458,534,747,591,218,545,571,183,157,946,557,622,126,866,396,591
108,261,879,156,842,466,285,738,771,595,52,55,463,518,665,750,880,798,778,703
90,322,517,743,456,911,579,290,923,126,848,868,599,870,628,590,120,544,353,546
861,477,711,754,420,357,257,880,689,559,748,627,508,171,770,469,223,728,884,414
60,538,906,571,902,494,284,493,258,745,124,684,94,646,451,90,850,180,175,514
475,866,326,566,937,975,846,491,456,158,830,403,349,583,557,57,535,883,641,493
498,580,467,116,614,615,629,161,528,454,81,474,843,640,740,96,848,544,99,530
526,628,678,725,881,394,742,773,837,762,414,363,211,550,52,106,60,619,61,539
152,618,802,64,205,828,480,595,898,895,479,527,395,281,95,301,117,357,839,855
749,760,326,866,176,127,184,610,524,703,365,82,559,68,118,828,558,587,520,170
905,457,569,641,610,849,226,223,517,740,407,843,905,738,360,115,92,228,59,987
126,744,503,144,929,684,617,322,220,607,590,584,687,127,941,228,881,415,500,945
475,495,582,51,57,595,400,217,646,134,50,153,185,212,698,876,228,347,736,604
518,770,797,608,499,906,702,946,622,173,820,580,564,68,601,774,728,625,894,932
320,700,588,572,539,470,570,548,556,859,767,284,245,948,411,924,830,935,288,692
66,497,934,756,122,550,948,692,590,867,104,402,551,766,165,637,405,214,184,288
363,675,211,426,549,115,321,690,595,566,867,843,883,220,598,54,604,837,483,420
341,832,534,576,538,760,522,521,176,685,482,472,498,882,697,397,739,947,54,368
777,469,466,123,111,613,236,846,494,191,218,575,800,611,498,193,364,932,633,188
865,258,559,516,587,521,678,100,217,517,744,765,499,176,740,826,325,634,357,560
429,505,736,515,495,702,938,281,152,680,925,193,880,117,494,841,631,110,576,123
631,942,693,804,610,882,716,228,527,490,135,170,498,675,211,363,229,900,415,400
62,900,736,564,483,99,512,946,210,209,767,92,833,187,117,412,898,627,749,711
768,427,536,695,639,730,604,713,470,699,692,555,748,865,216,95,642,630,496,877
505,626,759,772,151,590,227,505,849,680,551,580,203,223,836,579,754,408,288,168
582,556,557,870,573,352,601,455,422,406,133,548,125,874,866,126,65,497,447,902
174,62,357,591,219,836,528,588,903,129,864,335,525,851,124,731,397,754,880,104
286,179,703,646,261,192,475,568,700,803,630,761,349,360,529,769,876,330,797,407
575,63,937,450,943,129,484,399,159,642,942,462,417,368,406,506,694,990,702,570
640,771,349,527,99,353,905,590,897,599,488,89,804,768,526,450,516,827,562,202
852,584,998,584,584,406,726,868,554,690,587,349,451,69,104,733,397,183,773,156
554,445,220,417,758,385,797,519,637,55,734,415,838,697,487,871,614,884,836,495
425,881,508,865,497,774,598,102,134,322,360,350,676,408,211,559,606,416,474,460
288,204,800,943,774,752,302,362,729,349,132,877,499,132,511,414,935,64,120,769
864,638,568,282,504,646,394,114,774,580,325,513,552,258,413,868,905,826,155,469
114,464,747,63,428,822,829,503,846,551,695,413,355,68,929,503,501,767,493,948
583,577,250,55,521,542,777,507,613,630,109,678,635,752,804,700,875,495,938,410
898,217,596,764,944,404,180,555,642,903,861,361,394,613,65,570,170,453,524,564
401,849,744,590,545,161,503,568,159,286,327,213,865,348,529,686,330,769,423,327
841,743,944,323,898,538,505,593,929,578,322,169,553,406,426,616,539,445,120,630
861,470,636,747,468,900,619,897,548,310,939,171,111,755,328,901,360,409,553,183
60,878,648,929,580,54,89,499,135,552,449,735,470,776,906,530,745,767,740,185
221,496,747,508,894,421,535,289,800,457,257,176,517,422,549,114,534,287,686,489
210,396,367,87,588,404,112,157,761,767,353,105,906,9,527,174,634,178,619,605
699,406,577,742,561,589,544,289,864,93,333,732,726,61,583,428,605,261,684,360
353,422,898,168,214,281,738,363,462,674,194,469,554,571,876,566,445,498,159,259
88,684,191,496,512,121,632,538,675,456,745,306,935,773,497,550,778,853,933,756
285,399,191,364,132,634,545,799,428,106,450,802,906,613,520,983,931,526,526,128
393,351,222,184,126,290,874,492,799,189,483,947,24,61,568,355,751,680,848,939
850,550,321,705,621,882,401,362,180,539,804,568,466,356,451,50,863,902,525,400
626,364,59,727,610,356,112,172,518,594,213,157,949,480,501,171,182,133,271,284
683,329,328,173,903,686,830,853,69,893,633,897,327,492,874,365,982,834,581,167
158,631,725,732,94,157,100,924,847,122,547,21,520,855,572,494,928,726,510,604
448,416,521,295,804,260,833,885,897,257,107,285,697,186,94,133,327,926,395,695
499,360,700,18,217,323,50,462,100,66,399,635,327,516,935,399,534,451,680,727
871,561,559,151,745,638,735,165,540,506,676,941,167,200,491,797,485,357,462,159
882,678,465,103,803,885,322,517,630,742,258,189,274,942,93,183,395,771,691,421
777,683,112,67,686,934,410,449,729,699,477,192,749,116,559,66,653,743,601,158
873,874,327,695,835,366,675,729,166,545,613,142,162,219,593,546,427,152,902,636
701,834,770,405,394,868,921,186,326,458,748,696,801,183,677,86,838,447,507,799
739,744,597,226,167,94,92,662,797,163,603,636,368,476,289,355,349,428,632,858
356,464,480,122,100,510,178,549,418,649,614,66,736,61,131,703,930,454,696,501
446,329,850,898,411,483,220,937,421,510,738,514,603,492,706,398,62,494,520,99
682,58,630,211,127,544,119,461,867,471,765,929,219,217,881,160,420,490,483,363
606,835,897,563,150,679,367,419,536,899,537,117,574,512,577,215,612,702,508,941
446,635,456,940,851,216,255,579,543,173,229,614,66,585,179,428,944,634,696,607
643,408,501,351,157,737,607,581,173,53,733,941,748,363,468,860,480,548,713,411
460,984,360,156,166,167,753,220,60,161,834,491,574,935,696,469,258,620,105,737
233,284,803,874,698,842,833,633,526,604,50,697,216,827,466,862,756,864,610,358
815,496,58,564,220,507,581,742,185,401,118,635,931,760,393,857,893,585,484,193
946,322,897,489,602,448,211,773,148,937,774,178,924,947,479,539,486,870,872,576
628,506,681,59,172,597,146,758,301,758,703,934,547,570,695,570,523,748,176,573
725,54,930,421,631,177,19,616,357,98,476,61,229,356,155,626,60,873,454,110
415,419,229,272,700,531,568,50,726,459,133,745,869,580,108,732,215,470,868,924
219,175,177,356,847,879,211,932,853,675,732,753,425,215,579,695,492,257,415,929
461,583,156,455,127,506,471,759,347,940,368,726,223,185,450,327,112,901,978,505
679,62,609,477,744,123,263,583,568,476,743,162,761,760,679,518,526,939,602,285
194,367,619,336,62,851,195,900,619,407,773,640,543,322,563,622,600,696,679,559
897,591,404,79,213,577,803,605,556,939,949,594,52,893,286,476,61,496,797,321
906,609,742,572,602,933,340,544,940,101,171,847,609,218,134,285,213,515,881,692
539,445,773,870,756,82,754,855,687,396,587,167,281,116,175,427,803,54,797,537
295,638,690,156,700,124,896,192,685,538,699,469,411,92,103,327,101,181,852,598
688,640,58,258,229,175,603,566,883,745,120,751,361,983,895,152,871,776,565,475
571,110,473,844,182,325,282,474,800,848,720,872,580,463,642,637,302,937,565,54
884,477,454,11,851,768,155,427,617,894,395,471,127,756,119,349,499,933,569,367
755,159,620,255,403,541,639,215,619,155,121,880,512,758,132,169,859,488,831,511
733,869,737,830,169,174,163,194,931,891,99,209,743,101,570,934,100,156,642,63
474,487,517,162,426,690,355,924,188,467,195,189,67,623,537,160,51,257,750,163
773,597,167,448,992,485,524,749,839,414,581,419,69,544,155,302,108,489,210,640
152,488,736,115,55,206,732,756,631,878,261,214,354,465,365,559,576,552,105,155
114,411,759,2,478,283,569,394,607,488,524,678,90,870,856,581,941,844,184,111
152,161,638,357,757,758,328,618,186,96,630,891,428,536,353,68,603,54,702,599
168,170,603,134,769,278,853,447,219,743,526,450,729,457,289,758,842,102,493,758
66,86,681,483,684,730,855,13,731,505,531,558,351,364,550,195,519,365,393,518
857,544,529,602,566,333,499,414,181,778,357,112,134,539,901,135,827,697,854,53
686,461,208,530,879,871,863,727,489,613,893,397,860,732,92,899,459,850,133,420
853,701,562,352,54,574,423,428,495,746,759,355,507,737,540,777,456,179,587,91
195,936,925,221,178,739,161,854,320,257,569,754,141,475,633,418,177,402,106,577
535,329,629,684,877,727,509,750,727,158,537,527,514,461,321,574,769,320,647,679
215,568,691,508,841,295,57,736,172,564,213,597,500,933,479,557,445,288,551,777
478,597,540,116,494,449,10,101,546,611,67,777,482,408,409,130,578,212,636,934
588,857,728,926,620,355,600,358,153,481,753,228,227,702,687,182,710,592,640,604
381,565,728,741,221,522,215,615,590,494,154,569,760,747,926,530,56,411,875,367
931,404,258,462,642,529,347,510,613,473,942,897,617,829,623,420,633,507,989,393
211,449,284,518,593,840,94,133,126,518,144,540,504,521,857,884,602,587,460,941
185,619,688,495,594,748,617,398,626,862,491,207,850,60,548,623,641,777,393,411
898,404,559,524,461,488,898,773,870,59,641,778,528,399,462,54,67,450,82,498
64,588,21,287,465,621,542,452,584,568,745,841,639,395,878,86,120,635,760,481
734,282,753,261,469,180,114,578,284,945,755,715,924,92,799,122,213,113,104,514
107,427,257,703,673,846,258,700,747,216,593,686,736,729,607,850,756,874,804,590
540,549,180,156,496,124,124,871,118,193,596,865,350,110,66,119,1,855,640,464
55,740,893,196,53,63,68,548,896,479,587,525,600,867,119,753,479,948,517,632
846,480,885,573,494,680,358,949,56,498,583,471,193,663,859,452,412,506,566,359
668,934,692,367,732,923,748,99,947,697,222,56,864,492,880,527,495,875,906,451
562,91,529,354,728,423,288,400,467,177,881,221,539,834,942,448,455,178,800,466
480,538,525,463,585,612,474,159,898,463,771,727,674,945,356,86,754,12,602,744
183,935,224,324,287,700,801,755,364,705,68,454,419,861,857,846,356,326,301,533
646,634,626,414,185,173,700,873,754,474,949,52,573,220,851,535,862,601,829,931
866,584,746,402,350,751,754,588,762,863,584,555,580,565,225,868,868,193,88,531
184,847,898,758,509,838,285,100,574,4,92,727,69,89,323,534,570,574,364,700
773,67,591,402,512,753,509,624,213,123,157,298,511,164,501,445,222,401,496,545
447,928,683,937,363,132,755,775,550,595,280,676,466,728,883,676,404,170,624,941
540,455,903,484,302,804,302,742,944,569,186,927,777,400,688,504,546,564,554,15
868,469,102,594,534,622,90,153,228,894,676,501,521,181,609,924,980,185,929,160
214,614,107,586,52,582,112,482,114,757,410,609,827,948,161,893,198,398,212,421
185,209,678,923,576,182,167,134,802,407,352,575,651,120,193,501,421,527,692,101
445,539,361,605,125,522,72,552,623,482,760,326,188,898,750,933,604,692,905,176
511,928,321,747,586,611,626,679,470,117,347,60,765,828,478,858,115,100,170,357
762,751,677,349,694,865,868,619,157,928,165,558,492,829,453,574,727,743,537,496
906,739,628,466,182,715,899,855,361,328,872,412,691,105,865,177,91,500,402,860
719,95,933,551,735,597,690,608,479,847,92,118,827,105,193,728,726,135,482,876
517,468,212,668,895,529,627,128,462,355,357,360,323,301,99,680,693,502,111,394
735,802,625,259,364,760,95,283,928,176,929,524,299,593,840,832,323,129,61,878
948,712,257,854,619,213,540,856,562,883,580,504,739,97,742,445,798,519,604,739
527,695,855,743,459,540,544,536,932,932,872,486,455,248,575,220,473,893,450,158
281,215,570,91,591,489,643,261,274,687,63,65,177,177,846,637,882,404,180,894
106,416,356,926,944,458,19,580,528,215,850,935,927,399,69,761,941,851,730,258
947,257,618,153,184,357,859,320,554,611,297,91,355,487,837,871,412,864,472,122
591,99,86,521,399,396,647,397,848,773,525,93,800,927,454,517,592,893,756,592
103,854,498,88,290,529,130,694,167,282,992,51,874,515,492,538,490,873,678,454
259,945,171,512,639,925,684,830,64,637,642,458,360,349,147,873,330,164,729,364
728,829,483,259,560,685,177,451,177,477,607,680,161,301,101,134,358,20,861,926
733,602,875,641,932,349,947,393,212,678,217,403,636,69,450,541,882,600,297,631
356,64,422,745,638,216,885,90,185,884,154,574,285,607,476,99,550,120,152,839
832,631,942,741,458,353,467,219,605,769,570,516,848,771,465,99,149,348,880,696
169,599,902,490,777,420,349,801,161,197,859,838,932,395,448,933,120,220,731,185
623,558,994,412,58,286,944,155,102,156,850,124,840,896,129,842,465,515,835,127
526,211,403,190,187,408,505,570,559,493,542,356,935,610,255,530,937,258,497,407
680,368,864,745,761,393,179,834,186,754,547,646,827,750,777,57,935,161,159,94
103,452,996,874,450,906,59,738,686,366,168,494,123,185,804,754,775,903,746,97
641,635,768,62,51,762,526,726,931,485,166,840,181,754,475,104,598,870,302,636
895,451,846,129,53,880,125,578,363,469,835,508,604,458,797,942,509,125,20,603
977,128,557,622,728,859,352,465,526,693,213,468,896,829,92,582,96,483,852,868
929,728,845,676,939,461,866,743,480,116,62,734,57,152,894,495,872,707,90,616
676,878,768,543,216,195,868,322,160,603,325,824,415,638,171,488,904,104,847,468
176,843,560,897,112,640,583,556,844,61,203,928,575,528,738,217,258,496,928,733
330,534,456,554,421,227,765,224,742,400,170,457,846,489,610,545,226,122,900,60
505,131,488,894,428,448,571,642,181,411,130,454,583,724,760,452,472,760,281,693
630,446,420,809,826,859,129,187,602,842,287,214,131,694,416,879,770,837,676,769
774,532,176,775,588,677,405,597,715,804,212,58,420,826,281,799,497,284,758,114
215,993,733,325,776,365,325,54,544,285,755,115,774,895,614,885,642,514,738,927
623,602,746,854,760,126,88,465,616,761,758,797,825,834,799,948,458,65,551,799
852,348,522,108,631,124,693,867,544,686,496,703,183,409,23,642,754,284,221,478
247,688,93,479,862,504,290,467,325,535,215,857,925,362,160,112,286,323,96,542
940,353,688,568,903,156,693,877,877,121,624,178,91,140,514,94,532,761,538,744
157,116,217,904,591,552,555,133,729,566,759,248,358,841,522,925,484,163,544,740
417,842,119,612,135,595,815,801,939,906,571,446,557,800,800,617,512,124,586,64
701,604,904,365,252,745,54,566,700,551,689,753,943,477,510,349,492,216,505,118
849,61,899,97,723,642,797,546,105,92,289,832,596,578,108,125,212,281,948,358
214,482,749,168,614,640,208,594,533,574,620,353,590,852,830,57,449,412,628,322
354,776,725,902,412,177,448,682,610,422,462,799,106,213,840,860,410,767,475,321
926,550,130,870,466,255,190,491,322,589,260,837,758,844,478,115,59,638,831,490
215,367,184,170,223,882,511,615,807,748,324,832,416,103,742,801,475,553,851,96
884,394,856,591,564,258,135,835,254,187,497,857,547,681,59,486,506,681,494,827
138,573,394,531,356,105,839,731,593,680,614,523,404,594,65,455,330,221,489,619
881,687,461,352,469,159,174,423,192,539,508,350,535,415,112,905,862,169,679,850
416,488,681,546,606,139,760,427,868,541,616,599,900,504,561,528,505,702,742,948
588,260,559,611,158,153,182,497,901,648,840,94,803,406,627,903,519,513,643,212
870,934,586,799,161,638,852,173,608,322,422,289,925,726,499,468,445,111,897,883
505,881,593,155,448,101,524,206,513,176,736,926,591,68,466,490,895,163,287,259
606,540,415,448,602,400,399,557,859,599,660,325,803,837,288,876,160,690,932,498
528,693,869,93,998,940,865,571,161,185,452,800,701,415,480,521,169,456,802,867
396,534,841,880,727,560,445,737,745,292,326,471,578,288,519,943,871,585,64,949
866,703,281,358,944,994,457,750,627,587,507,680,473,544,933,535,850,211,852,606
547,580,409,510,588,307,517,219,520,757,944,689,126,768,481,189,55,827,874,366
615,560,417,185,924,170,744,415,932,344,88,355,847,490,221,831,395,192,498,773
934,943,836,676,489,173,293,736,471,641,288,500,680,194,596,186,555,228,109,420
914,602,902,874,218,129,492,689,738,118,121,751,942,874,893,855,778,545,857,544
457,325,531,881,682,526,837,223,751,642,209,488,937,410,587,944,547,746,821,352
777,836,861,64,328,506,68,351,365,827,164,351,169,181,930,738,677,690,988,834

View File

@ -32,5 +32,5 @@ def part2(inp):
print(f"Cumulative product of tress : {tree_product}")
if __name__ == "__main__":
#part1('./input.txt')
part1('input.txt')
part2('input.txt')

View File

@ -1,5 +1,6 @@
#! /usr/bin/env python3
from itertools import product
from bisect import bisect
def main(filename):
@ -23,34 +24,42 @@ def part1(results):
def part2(results):
seat_ids = sorted(x[2] for x in results.values())
missing_seat_ids = set(range(max(seat_ids))) - set(seat_ids)
print(missing_seat_ids)
print("Your seat id : ", max(missing_seat_ids))
def parse_boarding_pass(boarding_pass):
row = _parse(boarding_pass[:7], "F", "B", 128)
col = _parse(boarding_pass[7:], "L", "R", 7)
def parse_boarding_pass(boarding_pass, strategy="binary"):
"Poor man's dispatcher"
try:
to_call = globals()[f"parse_boarding_pass_{strategy}"]
return to_call(boarding_pass)
except KeyError:
raise KeyError(f"Bad strategy name {strategy}")
def parse_boarding_pass_binary(boarding_pass):
"Parse boarding pass using a binary conversion"
boarding_pass = boarding_pass.translate(str.maketrans("FLBR", "0011"))
row = boarding_pass[:7]
col = boarding_pass[7:]
return int(row, base=2), int(col, base=2)
def parse_boarding_pass_bisect(boarding_pass):
"Pass boarding pass using bisection algorithm"
row = bisect(boarding_pass[:7], lower_option="F", upper_option="B", max=127)
col = bisect(boarding_pass[7:], lower_option="L", upper_option="R", max=7)
return row, col
def _parse(inp, lower_option, upper_option, number):
rows = slice(0, number - 1)
def bisect(inp, lower_option, upper_option, max):
min_v, max_v = 0, max
for l in inp:
length = max_v - min_v
if l == lower_option:
rows = lower_half(rows)
else:
rows = upper_half(rows)
return rows.start
def lower_half(sl: slice):
length = sl.stop - sl.start
return slice(sl.start, sl.start + length // 2)
def upper_half(sl: slice):
length = sl.stop - sl.start
return slice(1 + sl.start + length // 2, sl.stop)
max_v = min_v + length // 2
elif l == upper_option:
min_v = 1 + min_v + length // 2
return min_v
def get_seat_id(row, col):
return 8 * row + col

View File

@ -1,5 +1,5 @@
#! /usr/bin/env python3
from day6 import parse_boarding_pass, get_seat_id
from day5 import *
def tests():
inputs = {
@ -9,8 +9,13 @@ def tests():
"BBFFBBFRLL": (102, 4, 820)
}
test("bisect", inputs)
test("binary", inputs)
def test(strategy, inputs):
for boarding_pass, expected in inputs.items():
row, col = parse_boarding_pass(boarding_pass)
row, col = parse_boarding_pass(boarding_pass, strategy=strategy)
seat_id = get_seat_id(row, col)
assert row == expected[0]
assert col == expected[1]

47
day7/day7.py Normal file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python3
import re
from collections import defaultdict, deque
def main(inp):
with open(inp) as input_rules:
rules = parse_rules(input_rules)
reverse_rules = build_reverse_rules(rules)
print(part1(reverse_rules))
print(part2(rules, "shiny gold"))
def parse_rules(input_rules):
rules = {}
for input_rule in input_rules:
color, rule = input_rule.split(" bags contain ")
rules[color] = {color: int(number) for number, color in re.findall('(\d+) (\w+ \w+)', rule)}
return rules
def build_reverse_rules(rules):
reverse_rules = defaultdict(list)
for bag, inner_rules in rules.items():
for c in inner_rules:
reverse_rules[c].append(bag)
return reverse_rules
def part1(reverse_rules):
queue = deque(("shiny gold",))
may_contain_shiny_gold = set()
while queue:
color = queue.pop()
for c in reverse_rules.get(color, []):
if c not in may_contain_shiny_gold:
may_contain_shiny_gold.add(c)
queue.appendleft(c)
return len(may_contain_shiny_gold)
def part2(rules, color):
return sum(number + number * part2(rules, c) for c, number in rules[color].items())
if __name__ == "__main__":
main("input.txt")

594
day7/input.txt Normal file
View File

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

49
day8/day8.py Normal file
View File

@ -0,0 +1,49 @@
#! /usr/bin/env python3
def part1(instructions):
instruction_pointer = 0
accumulator = 0
visited_instructions = set()
while instruction_pointer not in visited_instructions: # return before executing any instruction a second time
if instruction_pointer >= len(instructions): # stop the program when ip is out of bounds
break
visited_instructions.add(instruction_pointer)
instruction, argument = instructions[instruction_pointer].split(" ")
if instruction == "acc":
accumulator += int(argument)
instruction_pointer += 1
elif instruction == "jmp":
value = int(argument)
instruction_pointer += value
else:
instruction_pointer += 1
return instruction_pointer, accumulator
def part2(instructions):
for index, line in enumerate(instructions):
permutation = generate_permutation(instructions, line, index)
if permutation is None:
continue
instruction_pointer, accumulator = part1(permutation)
if instruction_pointer == len(permutation):
return accumulator
def generate_permutation(instructions, line, index):
permutation = instructions[:]
instruction, arg = line.split(" ")
if instruction == "acc": # don't replace acc operations
return
elif instruction == "nop":
permutation[index] = f"jmp {arg}"
elif instruction == "jmp":
permutation[index] = f"nop {arg}"
return permutation
if __name__ == "__main__":
instructions = [line.rstrip() for line in open("input.txt")]
print("Part 1 : (ip, acc) ", part1(instructions)[1])
print("Part 2 : (ip, acc) ", part2(instructions))

608
day8/input.txt Normal file
View File

@ -0,0 +1,608 @@
jmp +232
acc +21
nop +120
jmp +239
acc +18
acc +41
jmp +72
acc +47
jmp +314
jmp +1
acc +47
nop +175
acc +33
jmp +115
nop -5
acc +37
acc +25
acc +18
jmp +304
acc +0
acc +16
jmp +77
acc +9
acc -3
jmp +93
acc +16
acc -15
jmp +110
jmp +76
acc +36
acc +11
acc -3
jmp +258
jmp +241
acc +42
jmp +514
nop +103
acc +36
acc -18
jmp +47
acc +5
acc +37
jmp +480
acc -16
jmp +1
nop +498
jmp +1
jmp +12
acc +0
acc +35
jmp +437
jmp +326
acc -15
acc -7
nop -2
jmp +548
jmp -4
jmp +395
jmp +258
acc +37
acc +17
acc -18
jmp +345
acc -18
acc +37
acc +36
jmp +217
acc -4
acc +39
jmp -35
jmp +252
jmp +1
nop +91
jmp +402
nop -40
jmp +371
jmp -72
jmp +9
acc +41
jmp +95
nop +252
nop +30
jmp +240
nop +266
jmp +462
jmp +137
acc -14
jmp +203
jmp +1
acc +45
acc -14
acc -6
jmp -9
acc -15
acc +6
nop +298
jmp -56
jmp +14
acc +32
jmp +40
acc +17
nop +62
acc +14
jmp +119
acc +49
jmp -29
acc +27
acc -12
acc +14
acc +19
jmp +253
acc +19
jmp +345
acc -17
acc +39
jmp +1
jmp +133
jmp +268
acc -14
acc -16
acc +45
jmp +373
jmp +116
jmp +245
acc -19
acc +32
jmp -22
jmp +105
acc -9
acc +27
acc +16
nop +397
jmp +110
acc +13
acc -10
acc +10
jmp -69
jmp +29
jmp +94
acc +38
acc +49
acc +40
jmp +261
acc +43
acc -13
jmp +214
acc -10
nop -80
acc +15
jmp +228
acc +0
jmp +275
jmp -69
acc +46
acc +4
acc +24
acc +6
jmp +279
acc -9
nop +281
jmp +286
acc -4
jmp +306
jmp +342
acc -14
jmp +357
acc -10
nop -9
acc +10
acc +40
jmp +427
acc +0
acc +32
jmp +405
acc +45
acc +34
nop +281
acc +34
jmp +394
acc +41
acc +20
jmp -98
jmp -60
acc -3
acc +17
jmp +19
acc +6
nop +168
acc +35
jmp -141
nop -62
acc +8
acc +16
jmp +117
acc +34
acc -8
acc +35
acc -15
jmp +85
acc +2
acc -9
acc -4
acc +49
jmp +394
nop -145
acc +47
jmp +16
acc +10
acc +0
jmp +87
nop -88
acc -9
acc -16
acc +45
jmp +374
acc +28
acc +38
jmp -139
acc -13
acc +13
jmp +143
jmp -135
jmp -4
jmp -130
acc +5
nop -196
jmp +48
acc -10
jmp +149
acc -14
jmp +210
jmp +325
acc +45
acc +11
acc -15
jmp +97
nop +107
jmp -98
acc -7
acc -18
jmp -181
jmp +122
acc -15
jmp -49
jmp +1
acc +36
acc -10
jmp +1
jmp +62
acc +39
jmp +105
acc +19
nop +253
acc -11
acc -9
jmp +77
acc +50
acc +3
acc -18
acc +17
jmp +56
nop -209
nop +272
acc -13
jmp +270
nop +229
acc +12
jmp +1
jmp -44
acc -13
jmp +1
nop +275
acc +45
jmp -254
acc -2
acc -2
nop -148
jmp -91
acc +2
nop -30
acc -8
acc +0
jmp -96
nop +1
jmp -74
acc -19
acc +10
acc +26
acc +30
jmp -280
acc +46
acc -2
acc -8
jmp +277
acc -9
jmp +205
acc -13
acc +10
jmp +1
jmp +219
acc +38
acc +24
acc +11
jmp -129
jmp -86
jmp +1
acc +0
jmp +1
acc +46
jmp -135
nop +218
acc -14
acc +0
jmp +55
acc +24
jmp +213
acc +19
acc +16
jmp -266
acc +24
acc +15
jmp +158
acc +3
jmp -94
acc +16
acc +24
acc +42
jmp +201
jmp -32
acc +34
nop -321
jmp +212
acc +12
acc +41
jmp -212
acc +32
jmp +236
acc +45
nop +253
jmp +129
nop -3
acc +38
jmp +35
acc -15
acc +21
acc -7
acc -6
jmp +46
jmp -5
acc +5
acc +4
acc +42
jmp +142
acc +36
jmp -180
acc +23
jmp -46
acc +12
jmp +5
jmp +201
acc +36
acc -14
jmp -30
jmp -338
acc +12
acc +34
acc +2
jmp -310
acc -15
jmp -104
jmp -148
jmp +108
acc +37
acc -6
acc +0
acc +13
jmp -324
acc +49
acc +37
acc +37
jmp +131
acc +2
acc +30
acc +12
jmp -238
acc -12
acc +4
jmp -155
acc +45
acc -10
nop -168
nop +114
jmp +113
acc +15
acc +41
acc +6
acc +34
jmp +25
acc +46
acc +28
acc +44
acc -3
jmp -70
acc +2
acc +37
jmp -101
jmp +51
acc +45
nop -399
nop -60
jmp -391
acc +41
jmp -57
jmp -54
acc +46
jmp +90
acc +6
jmp +83
acc +37
jmp +1
acc -6
jmp -189
acc +0
jmp -241
acc +35
jmp -396
acc +35
acc +42
acc +37
acc +20
jmp -81
nop +74
acc +41
acc +23
jmp +1
jmp -349
jmp -232
acc +37
acc +24
jmp +121
jmp -144
acc +35
acc +39
acc -12
acc +14
jmp -113
acc +2
acc +29
acc -6
acc +0
jmp -326
jmp -426
acc +18
acc +39
acc +22
jmp +79
jmp +23
acc -17
nop +42
acc -8
jmp -47
acc -12
jmp -276
jmp -126
acc +20
acc +3
acc +41
jmp -31
acc -1
jmp +1
jmp -241
acc +9
acc +12
acc +0
jmp +26
acc +30
nop +46
jmp -134
jmp -361
acc +50
nop -1
nop -225
jmp -226
acc +42
acc +0
jmp +1
jmp -170
acc +14
acc +19
jmp -199
nop +15
acc -11
acc +20
jmp -161
nop -348
acc -6
acc +49
jmp -468
acc +11
jmp -413
acc -11
acc -1
acc +45
jmp -181
jmp -380
nop -128
acc +40
jmp -179
acc -9
acc +24
jmp -358
acc +50
acc +13
acc -15
jmp +14
acc +4
acc +12
jmp -365
nop -269
jmp -443
nop -224
jmp -108
acc +46
acc -11
jmp -515
acc -8
nop -284
jmp -444
acc +15
nop -11
jmp -288
acc +28
acc +35
jmp -416
acc +27
acc -8
acc -10
acc +0
jmp -167
acc -9
acc +42
acc +20
jmp -63
jmp -107
acc -6
jmp -335
jmp -460
acc -2
jmp -420
acc +27
acc +6
jmp -458
acc +31
nop +19
nop -396
jmp -479
nop -234
acc +42
jmp -142
jmp -511
nop +28
acc -9
acc +36
acc +38
jmp +27
acc -3
acc +9
acc -19
acc +3
jmp -133
jmp -503
jmp -267
acc +40
acc +41
acc +13
nop -492
jmp -327
jmp -339
acc +17
acc +4
acc +45
acc +13
jmp -419
acc +31
acc +0
acc +37
acc -13
jmp -210
jmp -517
acc -15
jmp -47
acc -16
jmp -129
acc +16
nop -455
nop -263
jmp -74
acc +5
acc +20
acc +45
acc +23
jmp -490
jmp -53
acc +40
jmp +1
acc -14
acc -1
jmp +1

50
day9/day9.py Normal file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python3
import itertools
def part1(inp):
preamble_size = 25
with open(inp) as infile:
cleanfile = (int(l.rstrip()) for l in infile)
for nums in window(cleanfile, preamble_size + 1):
candidate = nums[-1]
if not test_number(candidate, nums[:-1]):
return candidate
return -1
def window(seq, n):
it = iter(seq)
result = tuple(itertools.islice(it, n))
if len(result) == n:
yield result
for elem in it:
result = result[1:] + (elem,)
yield result
def test_number(num, previous):
sums = set(sum(x) for x in itertools.combinations(previous, 2))
return num in sums
def part2(infile, target: int):
lines = [int(l.rstrip()) for l in open(infile).readlines()]
total = 0
visited = []
for index, _ in enumerate(lines):
i = index
while total < target:
total += lines[i]
visited.append(lines[i])
i += 1
if total == target:
return max(visited) + min(visited)
visited.clear()
total = 0
if __name__ == "__main__":
invalid_number = part1("input.txt")
print("part1 ", invalid_number)
print("part2 ", part2("input.txt", invalid_number))

1000
day9/input.txt Normal file

File diff suppressed because it is too large Load Diff