Added 2021 (python)

This commit is contained in:
Karma Riuk 2023-08-02 11:46:44 +02:00
parent 410815acf8
commit 11600f7ba9
82 changed files with 8693 additions and 0 deletions

1
2021/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
__pycache__/

19
2021/00_template/prog.py Normal file
View File

@ -0,0 +1,19 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [int(line.strip()) for line in f.readlines()]
def result(inp, part = 1):
res = 0;
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 1))

10
2021/00_template/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 7)
# def test_part2(self):
# self.assertEqual(result(get_input(sample = True), part = 2), 5)

2000
2021/01/input Normal file

File diff suppressed because it is too large Load Diff

25
2021/01/prog.py Normal file
View File

@ -0,0 +1,25 @@
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [int(line.strip()) for line in f.readlines()]
def result(inp, part = 1):
res = 0;
if part == 1:
prev = inp[0]
for cur in inp[1:]:
if prev <= cur:
res += 1;
prev = cur;
else:
prev = 0
for cur in range(1, len(inp) - 2):
if sum(inp[prev:prev+3]) < sum(inp[cur:cur+3]):
res += 1;
prev = cur;
return res
if __name__ == "__main__":
print(result(get_input(), part = 2))

10
2021/01/sample_p1 Normal file
View File

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263

10
2021/01/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 7)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 5)

1000
2021/02/input Normal file

File diff suppressed because it is too large Load Diff

32
2021/02/prog.py Normal file
View File

@ -0,0 +1,32 @@
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
tmp = [line.strip().split(' ') for line in f.readlines()]
return [[e[0], int(e[1])] for e in tmp]
def result(inp, part = 1):
hor = dep = 0
if part == 1:
for [cmd, n] in inp:
if cmd == "forward":
hor += n
elif cmd == "down":
dep += n
elif cmd == "up":
dep -= n
else:
aim = 0
for [cmd, n] in inp:
if cmd == "forward":
hor += n
dep += n * aim
elif cmd == "down":
aim += n
elif cmd == "up":
aim -= n
# print(f"{cmd} {n}")
# print(f"\t{aim = }, {hor = }, {dep = }")
return hor * dep
if __name__ == "__main__":
print(result(get_input(), part = 2))

6
2021/02/sample_p1 Normal file
View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2

10
2021/02/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(True)), 150)
def test_part2(self):
self.assertEqual(result(get_input(True), 2), 900)

1000
2021/03/input Normal file

File diff suppressed because it is too large Load Diff

55
2021/03/prog.py Normal file
View File

@ -0,0 +1,55 @@
VERBOSE = False
def get_input(sample = False, part = 1):
global n_bits
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
tmp = f.readlines()
n_bits = len(tmp[0]) - 1
return [int(line.strip(), 2) for line in tmp]
def verbose(s):
if VERBOSE:
print(s)
def filter_by(most, inp):
global n_bits
for i in range(n_bits - 1, -1, -1):
dic = {0: [], 1: []}
for n in inp:
dic[(n >> i) & 1].append(n)
verbose(dic)
if len(dic[1]) >= len(dic[0]):
inp = dic[1 if most else 0][:]
else:
inp = dic[0 if most else 1][:]
if len(inp) == 1:
return inp[0]
def result(inp, part = 1):
global n_bits
if part == 1:
# print(n_bits)
tot = len(inp)
gamma = eps = 0
for i in range(n_bits):
ones = 0
for n in inp:
ones += (n >> i) & 1
a = 1 if ones > tot/2 else 0
gamma |= a << i
eps = (2**n_bits - 1) ^ gamma
return eps * gamma
else:
ox = filter_by(True, inp)
co = filter_by(False, inp)
verbose(f"{ox = }, {co = }")
return ox * co
if __name__ == "__main__":
print(result(get_input(), part = 2))

12
2021/03/sample_p1 Normal file
View File

@ -0,0 +1,12 @@
00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010

13
2021/03/test.py Normal file
View File

@ -0,0 +1,13 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_input(self):
self.assertEqual(get_input(sample = True), [4, 30, 22, 23, 21, 15, 7, 28, 16, 25, 2, 10])
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 198)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 230)

601
2021/04/input Normal file
View File

@ -0,0 +1,601 @@
79,9,13,43,53,51,40,47,56,27,0,14,33,60,61,36,72,48,83,42,10,86,41,75,16,80,15,93,95,45,68,96,84,11,85,63,18,31,35,74,71,91,39,88,55,6,21,12,58,29,69,37,44,98,89,78,17,64,59,76,54,30,65,82,28,50,32,77,66,24,1,70,92,23,8,49,38,73,94,26,22,34,97,25,87,19,57,7,2,3,46,67,90,62,20,5,52,99,81,4
7 42 22 92 60
8 88 99 13 12
16 62 86 24 77
20 57 19 67 46
36 83 54 63 82
7 86 50 78 16
83 45 67 94 58
21 98 99 85 43
71 19 31 22 4
70 51 34 11 61
4 95 84 51 36
43 40 37 23 85
14 90 8 59 99
0 88 68 93 81
25 6 55 19 48
15 39 78 6 13
71 3 81 95 62
22 46 67 72 40
89 69 0 37 41
68 79 58 16 42
63 50 77 34 12
29 42 20 17 47
80 10 30 72 66
5 89 64 25 21
91 88 45 44 37
78 89 32 26 56
8 40 54 25 49
36 30 21 23 3
12 58 2 29 7
33 99 15 84 44
96 68 56 49 43
55 22 16 91 32
2 17 61 12 37
25 72 1 31 88
57 34 42 8 71
18 39 86 94 60
96 85 64 51 28
48 14 23 36 35
6 84 99 90 81
43 41 74 68 32
9 58 60 7 61
96 33 67 0 19
77 2 14 99 79
13 36 90 95 29
86 91 49 72 20
3 79 24 37 97
86 10 77 31 32
48 89 35 73 94
65 21 23 82 36
26 51 69 12 99
66 28 73 6 32
11 30 35 42 76
33 40 25 89 52
46 88 55 50 64
86 71 75 36 80
36 34 35 68 49
61 3 24 84 71
47 42 91 39 80
25 51 38 59 62
90 21 28 52 8
19 93 45 40 55
41 11 79 9 70
16 87 32 22 94
12 4 72 60 0
36 77 78 33 83
43 44 7 39 96
30 75 62 63 8
19 12 40 68 45
50 27 3 52 57
85 67 33 16 36
33 16 66 9 7
93 34 52 31 13
3 49 94 39 37
76 59 78 51 83
40 47 22 42 73
44 60 52 7 38
36 53 79 11 93
46 65 40 68 58
67 73 99 31 87
22 49 33 59 75
83 61 17 60 86
38 33 96 75 22
19 42 76 55 97
93 94 29 50 88
34 16 91 3 40
92 48 40 69 98
12 46 37 25 78
43 11 34 22 32
0 18 17 86 1
89 26 65 76 96
66 48 43 99 98
68 2 51 87 38
72 77 47 20 97
36 18 80 10 96
88 53 30 65 91
10 3 65 38 56
40 14 64 45 23
42 88 31 85 17
19 83 46 51 5
35 47 28 0 50
75 53 9 1 29
92 94 41 82 38
39 70 80 11 56
64 28 27 22 60
66 97 48 65 71
91 17 37 49 83
66 1 79 87 60
78 46 32 30 57
50 56 23 6 24
13 89 42 70 77
59 28 58 56 73
22 4 53 91 23
8 41 36 52 80
30 68 34 70 63
90 3 61 98 1
50 76 99 74 81
57 25 59 69 96
26 15 43 64 44
73 18 61 91 23
87 13 46 90 60
63 1 77 93 47
12 90 56 46 0
57 73 79 87 43
32 13 53 37 14
22 3 23 78 69
49 55 93 57 2
67 12 81 70 79
60 44 94 23 54
48 92 99 1 82
76 36 62 32 98
94 15 97 55 17
39 40 84 92 49
72 45 52 95 96
61 58 88 23 78
80 48 37 35 66
86 88 20 12 7
72 52 95 34 11
1 47 83 63 18
25 35 76 15 92
96 64 82 54 31
61 83 5 24 36
88 80 48 26 85
2 42 70 98 45
27 6 65 94 15
71 73 3 47 38
85 49 19 41 53
4 99 43 93 60
34 28 78 23 50
54 79 35 25 94
27 63 16 51 39
89 49 13 1 32
85 87 8 38 64
14 5 63 16 27
23 76 43 59 94
78 80 83 15 54
26 66 73 74 64
9 81 62 75 25
46 13 55 43 1
0 2 10 58 34
76 11 82 42 16
68 93 18 99 84
96 25 44 69 97
24 80 74 27 6
33 14 54 17 28
10 47 2 63 59
12 56 29 63 0
30 94 5 19 18
9 13 24 72 60
91 46 49 47 51
8 54 26 7 21
36 16 26 97 56
22 86 58 94 89
66 84 50 82 53
87 29 45 95 33
49 61 46 2 52
87 35 65 27 69
12 98 94 18 26
22 79 1 74 84
0 72 29 70 19
96 28 95 25 77
79 95 3 91 44
57 61 77 80 29
6 49 37 62 16
71 73 21 52 48
92 17 32 2 43
29 78 6 94 47
83 63 68 16 56
38 85 92 60 35
81 57 75 79 7
69 22 93 49 4
93 21 2 17 22
76 70 3 80 51
7 88 14 0 61
18 16 29 86 74
65 47 8 45 46
1 20 23 79 14
27 76 3 90 85
88 35 7 10 92
67 97 59 41 8
56 57 65 45 81
57 14 41 89 55
47 75 90 23 94
26 3 40 17 97
65 44 12 4 30
16 81 64 79 13
63 3 22 7 10
36 76 14 77 38
48 27 40 9 60
31 56 75 74 78
86 64 71 90 67
52 28 9 19 66
15 86 61 2 89
93 3 44 46 91
11 7 5 32 72
60 10 92 29 88
88 86 59 8 68
10 48 12 61 21
54 97 45 55 11
67 9 22 64 5
7 34 32 69 44
69 45 14 6 3
16 32 33 26 73
79 30 5 1 72
64 9 60 59 22
23 56 37 41 2
25 65 60 87 39
41 53 24 91 93
43 59 26 78 96
16 33 88 18 7
74 63 34 30 20
38 23 97 73 35
51 31 90 98 80
56 44 60 8 7
71 10 87 0 99
64 30 20 22 18
61 57 31 69 74
94 0 96 90 59
21 3 72 81 4
43 41 58 45 2
62 7 65 71 19
60 20 19 48 11
2 68 58 91 76
57 12 52 29 13
42 53 38 64 81
26 70 16 32 54
15 93 68 77 49
80 64 45 10 94
30 62 5 66 40
46 51 52 22 56
7 90 14 6 47
75 87 31 24 11
47 61 14 69 50
33 44 12 26 58
91 10 35 5 29
99 81 16 92 53
50 37 47 13 83
63 96 30 36 86
72 66 93 73 74
98 60 3 84 28
52 14 70 21 55
65 19 32 28 92
9 8 51 0 98
56 26 53 13 86
2 70 16 52 4
69 10 97 38 79
34 48 46 66 44
59 19 18 20 13
99 26 62 16 2
91 25 11 84 4
52 31 70 71 14
92 1 49 65 77
85 8 27 87 84
41 73 81 15 58
14 93 33 17 52
35 90 37 38 0
11 46 2 20 31
97 50 12 79 96
89 77 57 61 40
65 75 4 33 17
66 81 47 83 98
34 57 44 0 99
32 25 17 48 90
27 73 63 61 81
50 22 4 28 41
6 24 70 13 45
96 18 36 16 10
37 11 50 56 88
80 40 75 90 12
19 43 33 61 58
30 59 99 69 98
31 77 98 90 51
34 10 80 73 97
2 37 33 17 0
59 78 91 87 45
86 7 44 64 1
26 49 66 13 16
95 89 52 88 55
77 60 3 93 73
64 45 98 38 42
34 86 1 71 68
59 71 24 18 99
23 28 88 54 26
90 37 6 76 4
41 64 27 89 67
29 95 82 83 60
8 0 90 41 61
29 66 2 35 13
12 9 5 36 93
67 94 82 77 37
30 42 32 80 78
53 6 23 57 38
8 25 76 18 15
19 17 20 48 72
26 54 64 7 40
50 94 82 67 99
93 5 67 10 4
77 80 97 14 2
34 9 61 24 21
63 89 28 76 62
54 29 38 68 69
72 48 66 89 22
63 39 71 59 68
2 95 94 21 92
6 28 44 62 15
35 78 80 11 91
82 8 59 66 25
84 87 95 60 12
9 52 83 28 49
23 34 85 94 96
43 41 39 2 73
81 56 55 29 70
94 96 7 90 2
95 45 28 75 12
48 83 65 22 91
68 98 5 41 73
36 22 45 14 74
35 60 54 15 30
86 49 27 82 4
87 2 52 50 21
39 62 40 1 19
99 7 85 24 65
26 17 36 35 1
2 62 38 45 48
72 68 32 59 11
28 53 64 21 76
61 63 94 50 55
34 42 39 66 37
22 72 18 89 12
16 23 4 0 41
75 64 3 44 5
87 82 53 5 19
26 54 36 1 38
28 30 48 97 95
34 91 99 23 8
46 35 33 29 66
76 89 94 77 58
24 31 1 40 25
44 71 42 61 8
16 41 28 33 50
6 85 66 43 51
91 28 70 89 43
1 76 26 90 45
24 2 6 82 23
77 68 16 51 81
58 86 52 29 18
95 0 25 19 91
10 65 30 72 42
41 8 77 58 23
94 60 34 11 67
24 1 64 78 44
40 76 21 37 15
44 26 80 77 88
25 72 38 34 9
75 81 43 86 68
59 30 87 61 73
0 63 62 82 93
70 61 14 56 3
54 43 92 78 27
26 7 99 77 73
21 30 44 50 40
2 60 45 17 73
75 67 68 20 18
16 30 24 37 12
79 50 8 65 19
85 95 54 90 47
69 68 54 66 17
39 19 20 33 44
12 27 50 60 36
53 81 8 7 87
82 97 18 4 74
58 63 8 42 28
70 95 39 54 61
30 56 79 37 82
15 32 83 27 45
52 13 90 97 62
11 50 56 66 84
96 94 57 17 49
68 58 90 34 59
81 36 91 8 45
62 35 6 93 48
82 89 54 87 80
94 6 45 53 62
31 34 58 85 77
24 25 91 99 26
41 0 59 37 23
93 41 53 31 87
7 22 39 86 73
71 34 60 57 6
52 64 48 99 90
66 76 62 45 40
5 84 85 67 26
11 1 0 95 21
48 59 43 94 62
22 74 40 49 89
51 20 90 78 96
0 45 43 79 25
41 10 95 86 80
4 60 82 33 75
44 46 38 17 76
22 58 27 73 66
54 50 7 92 79
11 43 38 94 5
63 80 33 58 4
12 91 28 70 97
26 99 41 52 90
23 26 95 8 17
73 77 61 89 82
78 80 64 19 96
81 92 47 44 59
54 24 63 74 32
86 85 37 80 45
47 44 92 29 49
67 48 95 51 88
36 8 56 16 30
0 97 84 24 13
81 61 42 87 92
30 75 17 67 2
83 44 96 52 1
37 78 31 15 19
40 9 72 7 28
10 85 17 38 22
46 35 90 12 27
76 42 7 2 30
55 57 60 9 49
79 73 97 1 21
52 36 11 82 91
22 7 46 21 12
62 42 66 68 10
31 18 76 20 84
28 79 61 39 86
73 99 34 54 45
43 28 18 76 40
57 58 63 9 11
89 65 2 12 90
38 97 49 15 27
28 84 24 17 49
33 69 75 53 92
81 48 89 19 34
59 1 18 72 79
6 22 2 86 85
72 78 30 40 19
54 16 25 81 28
41 99 7 79 14
83 76 29 8 91
5 60 11 51 37
77 78 34 59 29
62 69 54 8 97
80 53 25 66 85
81 90 31 51 52
63 41 57 68 18
43 62 11 41 7
37 44 34 10 51
67 36 61 77 70
59 1 25 42 88
29 71 60 15 24
30 65 57 35 84
34 33 72 73 28
38 51 4 52 14
58 59 85 87 39
88 81 11 93 71
19 5 23 71 75
70 9 57 69 14
49 29 22 28 10
42 48 63 73 6
79 18 4 39 88
16 27 31 88 86
29 40 65 68 39
15 95 93 69 22
66 48 18 84 11
7 51 92 96 99
0 69 51 12 82
4 81 62 2 49
27 66 95 83 70
94 97 99 63 19
87 75 77 73 44
82 83 75 95 53
46 47 31 14 64
71 70 11 51 87
7 16 63 38 29
89 13 33 41 0

101
2021/04/prog.py Normal file
View File

@ -0,0 +1,101 @@
VERBOSE = True
def verbose(s):
if VERBOSE:
print(s)
class Card:
def __init__(self, width: int, height: int, card: list):
self.width = width
self.height = height
self.marks_h = [0 for _ in range(height)]
self.marks_v = [0 for _ in range(width)]
self.won = False # for part 2
self.numbers = {}
self.card_h = [[0 for __ in range(width)] for _ in range(height)]
self.card_v = [[0 for __ in range(height)] for _ in range(width)]
for y, row in enumerate(card):
y = int(y)
for x, n in enumerate(row.strip().replace(' ', ' ').split(' ')):
x = int(x)
n = int(n)
self.numbers[n] = (x, y, False)
# verbose(f"{x = }, {y = }, {self.card_h = }, {self.card_v = }")
self.card_h[y][x] = n
self.card_v[x][y] = n
def is_row_full(self, row: int):
return self.marks_h[row] == 2**self.width - 1
def is_col_full(self, col: int):
return self.marks_v[col] == 2**self.height - 1
def mark(self, n: int):
if n not in self.numbers:
return False
x, y, _ = self.numbers[n]
self.marks_h[y] |= 1 << (self.width - 1 - x)
self.marks_v[x] |= 1 << y
self.numbers[n] = (x, y, True)
self.won = self.is_row_full(y) or self.is_col_full(x) # for part 2
def get_winning_sum(self):
ret = 0
for n in self.numbers:
if not self.numbers[n][2]:
ret += n
return ret
def __str__(self):
ret = ""
for row in range(self.height):
for n in self.card_h[row]:
ret += f"{n:2d} "
ret += f" {self.marks_h[row]:05b}"
ret += "\n"
return ret
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
lines = f.readlines()
ret = {}
ret["draws"] = [int(n) for n in lines[0].split(',')]
lines = lines[2:]
ret["cards"] = [Card(5, 5, lines[i:i+5]) for i in range(0, len(lines), 6)]
return ret
def result(inp, part = 1):
draws = inp["draws"]
cards = inp["cards"]
verbose(f"{len(draws) = }, {len(cards) = }")
n_won = 0 # for part 2
for n in draws:
for c in cards:
verbose(f"marking {n}")
if part == 1:
c.mark(n)
if c.won:
return c.get_winning_sum() * n
else:
if not c.won:
c.mark(n)
if c.won:
n_won += 1
if n_won == len(cards):
return c.get_winning_sum() * n
verbose(c)
return -1 # failed
if __name__ == "__main__":
# VERBOSE = False
print(result(get_input(), part = 2))

19
2021/04/sample_p1 Normal file
View File

@ -0,0 +1,19 @@
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
22 13 17 11 0
8 2 23 4 24
21 9 14 16 7
6 10 3 18 5
1 12 20 15 19
3 15 0 2 22
9 18 13 17 5
19 8 7 25 23
20 11 10 24 4
14 21 16 12 6
14 21 17 24 4
10 16 15 9 19
18 8 23 26 20
22 11 13 6 5
2 0 12 3 7

11
2021/04/test.py Normal file
View File

@ -0,0 +1,11 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 4512)
self.assertEqual(result(get_input()), 44736)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 1924)

500
2021/05/input Normal file
View File

@ -0,0 +1,500 @@
609,916 -> 60,367
349,494 -> 682,494
75,370 -> 397,370
55,623 -> 55,183
296,865 -> 296,235
810,691 -> 504,385
256,67 -> 256,468
446,679 -> 446,594
592,16 -> 98,16
866,642 -> 866,622
293,672 -> 911,672
799,855 -> 799,638
890,805 -> 389,304
454,263 -> 454,501
798,86 -> 540,86
331,256 -> 351,256
882,93 -> 445,530
879,163 -> 879,841
448,476 -> 96,476
230,198 -> 941,198
943,918 -> 70,45
666,502 -> 552,616
56,14 -> 978,936
438,284 -> 850,284
86,824 -> 86,277
170,461 -> 737,461
675,85 -> 675,289
289,14 -> 814,539
541,94 -> 541,868
334,391 -> 470,391
782,313 -> 358,313
165,301 -> 17,153
11,406 -> 11,869
758,365 -> 758,708
835,313 -> 212,936
636,387 -> 636,314
393,588 -> 393,694
193,639 -> 193,747
850,524 -> 557,817
465,751 -> 465,652
194,552 -> 194,380
212,270 -> 212,691
230,595 -> 581,595
135,698 -> 325,698
973,846 -> 333,206
508,297 -> 237,297
72,397 -> 418,397
159,921 -> 914,166
579,202 -> 370,202
375,86 -> 638,349
903,917 -> 14,28
43,841 -> 824,60
928,11 -> 478,11
562,129 -> 803,129
880,61 -> 564,377
967,949 -> 122,104
293,943 -> 293,484
674,466 -> 674,192
583,724 -> 834,724
499,888 -> 973,888
302,519 -> 470,351
793,284 -> 669,284
74,716 -> 799,716
517,529 -> 163,529
863,711 -> 863,91
977,988 -> 62,73
989,32 -> 370,651
795,627 -> 584,838
984,340 -> 96,340
780,425 -> 316,889
563,140 -> 378,140
203,55 -> 719,55
273,757 -> 763,267
836,901 -> 846,901
152,319 -> 136,319
92,970 -> 970,92
84,46 -> 498,46
539,408 -> 539,259
822,366 -> 694,366
586,819 -> 755,988
218,340 -> 218,812
394,197 -> 813,616
458,24 -> 401,24
684,92 -> 241,92
456,569 -> 746,859
611,961 -> 508,961
90,980 -> 90,423
21,13 -> 981,973
877,27 -> 354,27
583,327 -> 583,627
512,808 -> 662,958
688,832 -> 578,722
213,281 -> 901,969
473,42 -> 955,524
303,442 -> 614,753
829,831 -> 162,164
176,25 -> 952,801
23,12 -> 989,978
798,859 -> 710,859
140,784 -> 140,285
536,248 -> 536,917
950,753 -> 738,541
331,159 -> 778,159
834,385 -> 834,666
192,614 -> 650,614
820,503 -> 985,503
831,845 -> 62,76
653,606 -> 984,606
534,515 -> 969,515
105,824 -> 860,824
384,501 -> 486,603
425,337 -> 425,199
381,212 -> 381,704
897,890 -> 897,783
378,82 -> 564,82
630,940 -> 659,969
954,980 -> 815,841
718,111 -> 23,806
41,732 -> 426,732
346,671 -> 597,671
931,51 -> 32,950
875,738 -> 875,910
982,35 -> 97,920
646,341 -> 646,471
913,788 -> 745,788
979,11 -> 32,958
618,283 -> 618,382
386,47 -> 386,957
680,652 -> 430,652
26,752 -> 26,978
314,689 -> 941,62
806,366 -> 454,366
27,365 -> 184,365
461,915 -> 548,828
332,371 -> 878,371
446,208 -> 615,208
888,673 -> 888,288
529,975 -> 47,975
755,806 -> 489,806
297,108 -> 311,122
585,885 -> 968,885
334,359 -> 334,251
690,401 -> 637,454
131,522 -> 964,522
103,831 -> 378,556
621,327 -> 621,561
178,932 -> 979,131
452,285 -> 903,285
942,448 -> 919,448
102,966 -> 818,250
116,226 -> 746,856
855,799 -> 855,244
425,963 -> 387,963
548,879 -> 372,703
607,157 -> 607,611
949,15 -> 79,885
978,325 -> 639,325
887,605 -> 208,605
426,694 -> 426,296
498,960 -> 498,358
800,874 -> 800,529
172,106 -> 701,635
985,160 -> 985,473
804,34 -> 431,407
976,978 -> 10,12
865,761 -> 134,30
987,825 -> 987,746
110,730 -> 370,730
237,34 -> 814,611
292,700 -> 292,352
699,880 -> 699,286
611,94 -> 611,234
978,248 -> 354,248
517,600 -> 329,600
782,46 -> 218,610
31,15 -> 880,864
563,404 -> 472,404
696,552 -> 974,552
785,202 -> 861,202
94,829 -> 94,404
541,395 -> 531,395
248,810 -> 935,123
169,843 -> 169,870
557,35 -> 345,247
958,24 -> 835,24
130,333 -> 302,161
961,53 -> 87,927
485,285 -> 975,285
376,788 -> 260,788
378,590 -> 378,253
235,961 -> 406,961
93,170 -> 93,339
707,782 -> 475,782
385,719 -> 385,340
430,758 -> 412,740
169,780 -> 504,445
238,109 -> 238,383
805,603 -> 805,364
981,373 -> 458,896
514,203 -> 372,203
942,234 -> 855,234
446,292 -> 446,917
882,478 -> 882,394
690,768 -> 742,768
356,652 -> 356,891
675,751 -> 675,37
370,252 -> 574,252
777,736 -> 777,177
230,367 -> 787,367
187,274 -> 187,752
850,888 -> 23,61
356,258 -> 392,258
176,698 -> 434,440
133,813 -> 133,635
655,574 -> 909,574
365,771 -> 635,501
738,611 -> 378,611
322,85 -> 322,591
137,596 -> 137,522
686,339 -> 686,59
843,886 -> 963,886
967,639 -> 179,639
491,208 -> 491,950
396,526 -> 644,774
29,29 -> 986,986
250,40 -> 703,40
25,784 -> 757,52
443,582 -> 324,582
753,369 -> 404,369
987,966 -> 34,13
390,21 -> 983,21
861,626 -> 757,730
873,220 -> 873,459
529,646 -> 529,90
886,668 -> 682,464
315,310 -> 315,846
674,449 -> 674,594
719,448 -> 544,623
625,170 -> 182,613
242,498 -> 337,498
496,23 -> 793,23
258,240 -> 151,133
256,309 -> 110,455
312,438 -> 312,672
710,549 -> 710,920
967,719 -> 967,414
201,324 -> 632,324
902,167 -> 226,167
745,517 -> 677,449
548,18 -> 817,18
711,806 -> 672,845
907,554 -> 907,837
144,810 -> 698,256
549,247 -> 549,623
309,802 -> 330,823
528,275 -> 158,645
689,372 -> 689,448
621,60 -> 621,332
38,884 -> 892,30
117,898 -> 989,26
521,702 -> 521,42
985,142 -> 377,750
482,517 -> 562,517
333,168 -> 963,798
296,642 -> 564,642
112,541 -> 111,541
745,395 -> 474,124
279,238 -> 766,238
491,747 -> 491,616
973,462 -> 150,462
867,120 -> 867,966
854,498 -> 854,244
684,233 -> 929,233
120,151 -> 545,151
172,361 -> 630,361
100,219 -> 416,219
988,24 -> 27,985
969,160 -> 193,936
985,891 -> 158,64
284,875 -> 857,302
310,363 -> 310,544
841,902 -> 245,902
964,240 -> 435,240
787,358 -> 399,358
177,637 -> 177,250
397,61 -> 60,61
889,180 -> 409,180
631,899 -> 551,979
253,912 -> 253,876
916,700 -> 983,700
89,512 -> 515,938
516,940 -> 516,526
303,587 -> 303,698
287,323 -> 287,730
907,528 -> 907,722
450,118 -> 450,907
12,356 -> 12,875
210,34 -> 726,550
198,364 -> 198,506
314,242 -> 942,242
939,86 -> 198,827
783,959 -> 837,959
978,180 -> 979,180
72,668 -> 643,97
888,841 -> 888,712
553,166 -> 553,253
733,880 -> 733,805
921,36 -> 37,920
113,164 -> 909,960
27,746 -> 269,746
734,978 -> 734,158
334,249 -> 218,249
966,762 -> 773,762
971,862 -> 171,62
607,609 -> 607,880
140,261 -> 140,983
705,944 -> 906,944
691,617 -> 130,617
657,190 -> 657,84
228,840 -> 655,840
653,876 -> 311,534
620,337 -> 625,337
76,510 -> 220,510
39,980 -> 931,88
339,44 -> 179,44
292,830 -> 706,416
640,184 -> 441,184
583,238 -> 583,896
666,593 -> 502,593
317,750 -> 743,750
574,466 -> 679,466
636,348 -> 636,130
115,268 -> 443,596
411,664 -> 213,664
926,615 -> 452,141
258,232 -> 147,232
786,297 -> 181,297
780,271 -> 101,950
533,494 -> 159,120
478,286 -> 365,286
753,247 -> 933,247
334,937 -> 334,419
821,57 -> 821,647
970,68 -> 50,988
158,799 -> 158,598
574,632 -> 975,632
217,184 -> 880,184
443,130 -> 573,260
937,144 -> 240,841
129,547 -> 129,327
805,174 -> 900,174
650,335 -> 115,870
122,804 -> 679,247
104,829 -> 104,587
933,452 -> 71,452
181,469 -> 181,702
114,136 -> 890,912
649,144 -> 746,241
42,297 -> 592,847
721,572 -> 34,572
291,262 -> 960,931
154,503 -> 154,682
264,869 -> 264,626
310,421 -> 579,421
869,390 -> 448,390
223,737 -> 223,627
760,162 -> 760,210
484,465 -> 401,465
582,921 -> 582,75
31,905 -> 546,905
119,376 -> 119,58
76,520 -> 76,102
780,257 -> 590,257
873,796 -> 540,796
469,605 -> 421,653
188,667 -> 390,869
926,279 -> 926,638
22,959 -> 163,959
444,439 -> 444,647
923,513 -> 577,859
500,162 -> 374,162
143,988 -> 143,29
82,754 -> 82,982
107,911 -> 107,941
281,782 -> 638,782
740,445 -> 967,672
280,516 -> 280,882
203,157 -> 465,157
16,984 -> 982,18
122,823 -> 81,823
881,232 -> 881,78
33,94 -> 33,259
29,109 -> 695,775
24,593 -> 921,593
186,503 -> 186,243
369,561 -> 369,176
381,835 -> 462,835
838,911 -> 153,226
115,683 -> 115,444
429,145 -> 85,489
875,577 -> 365,577
221,539 -> 221,252
65,957 -> 65,468
112,175 -> 112,475
358,700 -> 676,700
428,508 -> 428,36
29,962 -> 977,14
941,16 -> 87,870
599,923 -> 683,839
918,244 -> 702,28
926,754 -> 262,754
455,139 -> 455,851
113,189 -> 113,235
429,441 -> 546,441
151,183 -> 929,961
804,335 -> 804,659
469,418 -> 469,235
103,99 -> 902,898
874,737 -> 595,737
728,451 -> 524,247
758,366 -> 758,690
765,40 -> 570,40
987,10 -> 19,978
601,881 -> 601,703
574,525 -> 826,777
690,223 -> 690,98
841,496 -> 715,496
33,32 -> 984,983
21,368 -> 21,209
883,473 -> 451,905
103,151 -> 198,246
102,72 -> 792,762
525,725 -> 679,879
276,742 -> 107,911
456,833 -> 456,714
781,769 -> 781,643
539,951 -> 324,951
467,803 -> 250,803
30,406 -> 258,634
399,475 -> 399,494
895,942 -> 515,942
512,591 -> 413,591
183,112 -> 687,616
439,860 -> 439,746
864,633 -> 708,477
846,137 -> 846,378
778,245 -> 330,693
309,458 -> 633,458
15,457 -> 440,882
563,466 -> 799,702
307,751 -> 307,723
665,987 -> 843,987
683,674 -> 683,497
644,354 -> 778,488
61,809 -> 735,135
18,124 -> 18,490
171,179 -> 171,216
99,372 -> 610,883
143,115 -> 871,843
385,688 -> 77,688
637,500 -> 637,896
409,905 -> 225,905
654,676 -> 474,676
946,81 -> 946,320
209,53 -> 209,535
757,508 -> 757,636
673,162 -> 255,580
526,593 -> 862,929
476,256 -> 739,256
879,954 -> 38,113
786,577 -> 141,577
672,131 -> 519,284
114,334 -> 212,334
571,49 -> 571,893
958,942 -> 41,25
369,545 -> 369,927
699,450 -> 244,450
15,538 -> 15,67
418,419 -> 90,747
335,758 -> 540,758
165,211 -> 165,357
534,347 -> 251,630
893,547 -> 893,119
475,581 -> 860,196
770,492 -> 879,492
131,973 -> 742,973
297,808 -> 297,490
12,974 -> 937,49
932,410 -> 802,410
40,535 -> 646,535
28,37 -> 951,960
270,506 -> 270,790
655,752 -> 839,752
979,220 -> 979,311
903,272 -> 234,941
960,786 -> 246,72
795,156 -> 99,852
784,285 -> 221,285
100,152 -> 100,910
481,628 -> 657,628

73
2021/05/prog.py Normal file
View File

@ -0,0 +1,73 @@
VERBOSE = True
def verbose(s = "", **kwargs):
if VERBOSE:
print(s, **kwargs)
def get_c(s: str):
c0 = s.split(',')
return [int(c0[0]), int(c0[1])]
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
tmp = f.readlines()
ret = {"coords": [], "map_dim": [0, 0]}
for line in tmp:
coords = line.split(' -> ')
c0 = get_c(coords[0])
c1 = get_c(coords[1])
ret["coords"].append([c0, c1])
ret["map_dim"][0] = c0[0] + 1 if c0[0] + 1 > ret["map_dim"][0] else ret["map_dim"][0]
ret["map_dim"][1] = c0[1] + 1 if c0[1] + 1 > ret["map_dim"][1] else ret["map_dim"][1]
ret["map_dim"][0] = c1[0] + 1 if c1[0] + 1 > ret["map_dim"][0] else ret["map_dim"][0]
ret["map_dim"][1] = c1[1] + 1 if c1[1] + 1 > ret["map_dim"][1] else ret["map_dim"][1]
return ret
def result(inp, part = 1):
m = [[0 for _ in range(inp["map_dim"][0])] for _ in range(inp["map_dim"][1])]
for c_pair in inp["coords"]:
x1, y1 = c_pair[0]
x2, y2 = c_pair[1]
if x1 == x2 or y1 == y2 or (part == 2 and abs(x2 - x1) == abs(y2 - y1)):
if x1 == x2:
for y in range(min(y1, y2), max(y1, y2) + 1):
m[y][x1] += 1
elif y1 == y2:
for x in range(min(x1, x2), max(x1, x2) + 1):
m[y1][x] += 1
elif abs(y1 - y2) == abs(x1 - x2):
d = (
1 if x1 < x2 else -1,
1 if y1 < y2 else -1
)
verbose(f"going through {x1, y1 = }, {x2, y2 = } with {d = }")
x = x1
y = y1
m[y][x] += 1
for _ in range(abs(y2 - y1)):
x = x + d[0]
y = y + d[1]
verbose(f"{x, y = }")
m[y][x] += 1
res = 0;
for row in m:
for cell in row:
if cell == 0:
verbose('.', end='')
else:
verbose(cell, end='')
res += 1 if cell >= 2 else 0
verbose()
verbose()
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

10
2021/05/sample_p1 Normal file
View File

@ -0,0 +1,10 @@
0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
3,4 -> 1,4
0,0 -> 8,8
5,5 -> 8,2

9
2021/05/test.py Normal file
View File

@ -0,0 +1,9 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 5)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 12)

1
2021/06/input Normal file
View File

@ -0,0 +1 @@
1,1,3,5,1,1,1,4,1,5,1,1,1,1,1,1,1,3,1,1,1,1,2,5,1,1,1,1,1,2,1,4,1,4,1,1,1,1,1,3,1,1,5,1,1,1,4,1,1,1,4,1,1,3,5,1,1,1,1,4,1,5,4,1,1,2,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,5,1,1,1,3,4,1,1,1,1,3,1,1,1,1,1,4,1,1,3,1,1,3,1,1,1,1,1,3,1,5,2,3,1,2,3,1,1,2,1,2,4,5,1,5,1,4,1,1,1,1,2,1,5,1,1,1,1,1,5,1,1,3,1,1,1,1,1,1,4,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,2,1,1,1,1,2,2,1,2,1,1,1,5,5,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,4,2,1,4,1,1,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,5,1,1,1,1,1,1,1,1,3,1,1,3,3,1,1,1,3,5,1,1,4,1,1,1,1,1,4,1,1,3,1,1,1,1,1,1,1,1,2,1,5,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1

35
2021/06/prog.py Normal file
View File

@ -0,0 +1,35 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return list(map(lambda x: int(x), f.readlines()[0].split(',')))
def create_state(l):
return [0 for _ in range(l)]
def result(inp, days = 80):
state = create_state(9)
for n in inp:
state[n] += 1
for _ in range(days):
zeros = state[0]
for i, n in enumerate( state[1:] ):
state[i] = n
state[6] += zeros
state[8] = zeros
res = 0
for n in state:
res += n
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), days = 256))

1
2021/06/sample_p1 Normal file
View File

@ -0,0 +1 @@
3,4,3,1,2

11
2021/06/test.py Normal file
View File

@ -0,0 +1,11 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True), days = 18), 26)
self.assertEqual(result(get_input(sample = True)), 5934)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), days = 256), 26984457539)

1
2021/07/input Normal file
View File

@ -0,0 +1 @@
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,1133,1029,1446,1005,596,277,439,544,201,317,237,33,252,774,482,291,57,1434,153,134,385,993,677,1189,99,1082,351,80,1563,195,581,693,5,633,184,552,11,606,462,48,134,1451,850,221,336,661,276,156,932,23,98,76,327,212,489,230,819,998,1037,1561,206,159,757,207,1203,224,1459,294,39,1108,96,89,1664,353,41,83,942,771,362,193,900,676,851,277,558,368,1054,316,143,464,85,896,558,52,669,163,696,140,340,542,817,783,1436,786,81,21,669,184,430,312,1500,797,698,611,314,145,125,391,785,867,488,144,9,967,560,245,116,96,1769,314,533,25,0,1375,1307,1273,1178,332,59,26,234,487,480,615,313,629,28,707,96,637,30,350,1286,900,777,115,56,79,809,1101,13,150,741,940,20,403,384,479,622,108,325,276,609,654,535,539,62,187,414,535,140,222,845,357,55,17,8,1430,853,759,331,673,202,482,1280,714,911,409,429,604,278,478,301,408,590,329,1482,110,423,488,7,628,66,196,399,86,241,1058,501,1284,594,710,799,34,60,668,457,0,1209,20,50,1134,288,415,399,86,540,1356,285,1541,172,3,634,1387,146,669,195,403,601,758,160,970,760,43,213,68,805,50,350,292,78,252,54,1021,882,241,808,601,892,878,1401,48,191,74,1429,94,520,505,679,1133,120,485,183,362,684,520,1366,301,123,290,1248,140,44,230,572,57,1101,217,906,1012,668,85,230,32,100,472,275,78,91,19,61,732,518,189,85,1531,1255,134,489,637,792,42,36,392,603,976,651,127,486,340,534,185,890,346,906,1295,319,321,597,252,183,554,124,44,426,131,408,582,429,645,1227,574,14,1828,359,184,1830,10,288,194,949,1578,492,502,149,609,77,92,320,233,1026,123,26,188,1123,4,665,1793,331,858,481,197,424,133,933,338,7,163,1269,665,19,1,538,126,895,1751,345,895,203,175,66,305,1479,239,718,386,8,1148,203,636,1211,635,149,489,1156,1828,61,328,331,287,262,8,3,522,1427,931,1103,199,329,930,779,124,446,391,903,696,1764,16,595,522,143,296,19,872,29,546,566,256,63,1195,862,516,267,452,1287,11,547,760,77,117,988,185,293,421,118,767,70,169,456,600,755,740,1799,97,507,1165,265,1126,376,1250,408,22,674,774,361,54,558,1021,529,29,871,527,474,218,47,309,61,188,1365,725,267,235,359,1004,1771,765,8,17,103,89,967,65,302,759,1688,882,709,1469,123,548,834,355,646,404,76,257,101,627,2,66,1328,137,42,23,127,110,632,683,1163,843,1119,16,497,1756,347,958,981,57,185,204,1403,530,536,104,68,1152,95,320,959,144,281,350,622,717,112,631,150,19,938,296,1272,825,37,192,350,847,306,824,1042,320,480,857,589,137,687,93,21,1601,547,550,491,161,49,124,292,396,34,24,95,932,56,968,197,109,1300,1326,605,357,412,14,179,450,991,173,120,1402,478,77,933,88,96,49,95,596,1885,841,441,659,309,418,87,134,34,815,759,631,209,728,7,232,1304,698,140,304,1448,101,1,239,1321,362,1367,1411,279,111,633,1347,110,18,710,443,1676,64,531,386,64,518,619,893,140,301,426,1451,261,1083,115,61,943,60,891,217,475,48,436,586,31,287,196,430,357,78,161,1533,745,198,715,8,307,225,604,263,992,371,749,700,1573,573,546,480,425,47,88,66,799,388,60,736,111,81,856,29,695,141,4,271,143,939,423,3,1260,265,24,903,292,23,80,196,1245,399,123,3,532,283,366,1175,187,15,450,487,117,1041,669,59,579,159,461,598,915,666,1231,999,253,185,1016,135,1317,253,111,1261,833,26,851,120,11,63,718,682,233,76,0,50,1678,777,286,279,90,47,158,71,35,475,245,550,4,942,1816,1646,102,175,343,12,446,12,623,44,157,10,555,1173,651,361,745,1870,97,237,1628,90,233,126,1596,1146,746,383,209,55,209,318,904,144,90,21,86,4,970,262,8,210,249,871,1216,1003,172,405,821,225,2,143,915,129,598,397,583,1400,315,113,33,75,426,2,611,293,196,419,125,176,496,4,607,1425,27,48,172,972,626,227,184,1257,514,209,524,22,58,927,4,931,3,6,104,716,961,17,4,154,249,558,203,180,180,1194,935,263,535,380,1439,274,1566,873,1763,2,89,636,407,667,438,966,757,245,730,328,915,167,245,126,52,652,938,1183,320,1298,10,844,36,263,382,37,142

29
2021/07/prog.py Normal file
View File

@ -0,0 +1,29 @@
VERBOSE = True
def verbose(s = "", **kwargs):
if VERBOSE:
print(s, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return list(map(lambda x: int(x), f.readlines()[0].split(',')))
def result(inp, part = 1):
res = -1
for mid in range(min(inp), max(inp) + 1):
score = 0
for n in inp:
delta = abs(mid - n)
if part == 1:
score += delta
else:
score += delta * (delta + 1) / 2
res = score if score < res or res == -1 else res
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

1
2021/07/sample_p1 Normal file
View File

@ -0,0 +1 @@
16,1,2,0,4,2,7,1,2,14

10
2021/07/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 37)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 168)

200
2021/08/input Normal file
View File

@ -0,0 +1,200 @@
cdafg dage fgdaec cdbfgae cge gcbdfa fdceb gfceab ge ecfgd | eg eg dfecag ge
efgcabd edacgf gfaec deg dg decga dcfg dbgafe bfgcae abced | deg baced fegac aefbcg
egacf dfbeg dec efcgd cfad cfagde fabcgde dc agbecf bgdeac | gcadef eacgbf egdfb bgdfe
dc cgefb cdf bdfgc adbc gafdec cbagfd gfbad dbcagfe gbedaf | cd cd agfbd bdac
dcbafg gadeb faegb cfbga ef gfe feca aegfbc cebgdf dfabceg | faec ceaf bcedgaf cfbga
bcf adbcef cbgdfe dbceag gcdbe dcafg egadcbf fb dgfcb gebf | cbgedf cbfdae aegbcd bf
dfge dg fbgce ecgfdb fcabdg bafgec cdg cbdae gecbd ecgdabf | eafcgbd gd cfgbde cdg
fadbg badfe faebcd gab ebfgad bfceag gfbcd gade adcebfg ag | gbfdea aedg becfad aedfbcg
gcfbd dga bfdcga gafdbec dcafg defac ag adbfeg acbg bfdecg | dbgeaf ga dagfeb fagdc
efdab cgadf cbafd fgbcda ebgfdc cfb bc gcba cefgad gfabcde | cagb fcdage bc dacfgeb
acgfe gcedbf fge dbfacg bgcfa fcbaegd ebga eg feacd egabfc | geab fgabc cfaegb egfcba
cef egcbd fbage cf bacf fecgba fbadegc fgdeab fcbge daegcf | dfaegc bedgc ecbdg becgf
acdb bdegc fgced dgb fbdgace agefcb cegdab dbgafe bd baegc | fedabg egcdba bcafeg fdageb
adbfce bfgc dfcebg efbdg cbefdga bdcge cb afgbde gceda cbd | ecgad egfdab dbc fgcb
dafgbe ecafg edcbfa fdcg cef fgade cf gecab gdacebf cedfag | bdcefag gfdea eacgb cf
acedgf becdgfa fgcae fdgac fdcgb aged gcfeba ebfdca ad adc | begfadc dfgac efagc fgcade
gefbd beafgc dabge fgad ag bdcegf agfebd gba acdeb dgacebf | ebfgda egdab febgd adgf
cdage gcebfda dea bceag de bfcdae egbd egbdac gebafc cadfg | ebdacfg agcbe adbcegf degacb
becf fcd cabdg gefdab dbgcf ebcgfd cf bgdfe edfcag egafdcb | gdcfbe gefbd eagfcd gbcfd
ec dagcf debag eagdc cfabed eca begc bfeadg dfcbaeg bgeacd | dcagf decgba eac cefabd
gace egadbfc bfecgd dce beadf decfa gcfdab fcdaeg ec afgdc | afecdg badfcg cfaedg adegfc
cfbge ac cea fdeab adfbgce fabceg dgfbce abcef acgb afecdg | bagc cfebg fbaec eca
gfdcba bcf ecfdg bc baefgd efbgac caeb aegfb cebfg badfegc | cfb cfb cfdge cbf
acg cagbdfe ca fgcadb agcebf cegfd acfgd dacb bdfga feadgb | edfgba fegdba gabfce bfegda
eabgfc gfeac dgaeb ecgdfba cba eabgc dfaegc cb cfgb cdbeaf | agfec ecfdga aegbc bedga
defgac eabdcf be faedg beag bgdfe gdebfa ebf bgcfd bgdceaf | dfgcb eb fdcaeg ebf
db cfdbaeg baecgd dfbega bdgaf afebg febd adfcg aebgfc bdg | fbaegc fbgae bfde abfdg
defbg cbdfeg dcbegaf cbdf cfe begca aegcfd ecgbf fc agdebf | bgfaed defagc efdgb cdfb
ecdafb dbf bgdea abcf fdaegc dabfe fgecbd fb deafc fdacbeg | afdbce facb bf fb
fa edfabg bfacd gcefdba fba agfc cfedb fagcdb agdbce adbcg | efcdb edgbaf cadgbf gcfa
cfb gcfbea bacgfde bc geadfb badc bedfa edbfc ebadcf gdfce | gbfdae fcbedag gaefcb cebdf
cfd gdeac ecbfagd cagdf fagcbd dafb egcfab bfgcde fagbc fd | fdba cagdfbe dafb dcf
fcageb fa gfa dbfa begdfc dcega gdbfe eafcdbg fdaebg afged | faedg gfa afegcb eabcdgf
feabc gf agdbe gedbaf fgbd gfbea becagd fge gadcfe cdeagfb | fgabed gf afcdeg aebdgc
dfebc gedfcb bcgfd fde dgbe afcdge dcgfab ed befca fbcaedg | bfcged fde febca dafbgc
ebafcd acbd cdebfg ead ecdbgaf edacfg efbag da fdebc fedab | cgbeadf bacd bcedfg gbcefd
beadgc bd gcfba adgce cfedgab bgd cgfdae agcbd gadbfe bdec | gebfad dbegfa cbafg dgfabe
fdecagb bdafce gbcfde egcbd ea eadg cbgae gbceda agcfb aec | cfabg cgfba cgdabfe cafgb
ca fegabc bdac gecdfb feabcd cea eafgd aefdc dgbaefc edcfb | fbdgec aec cbad adbc
baegfdc egb fcage bfcged bfdea gafecd gbac bg caegbf fegab | cfadebg bcgdfe gcbefd bgefa
fdabge faedcbg dfbea gfcade dfe de adbgfc egdb eafbc badfg | dabgf fcagedb gdabef de
bagcdfe dfaceb egdafb facegd cedbg ga dga bgaed fbag bdfea | bedcg afbged dfbea dcbeaf
cdbef caebf defabgc ecfbag cd dfc aced dbegf fcdbae bdgfac | ecgbfa cd dc ecfagb
facbdg dfgacbe bfcgd bcgedf bgead dec gfdeac fecb egbcd ce | gdbaefc bagcfed bcgdfea cdgbef
abcef ebfdc dfagcb dcbgef ba daeb ceagf dcaebfg faecbd fab | dabfce abf fgdaecb dfbce
cbe abecgf be gbacdf dacfebg eabcf aegcdb gabfc gfbe fdeac | ebcaf cdbfeag fcdea egfb
gfad degab fcgdbe aeg bfedg abdgfe gefacbd ga badce fagceb | cfbged efgcab bfdeag fdbeag
fgadbce edbag dgbcf dabfg fa fdaceg bacedg faeb bfadeg gaf | fa abfe bfdgae gdafcbe
afde cfadbg gcdbe bfdecag ea efbacg abe cfbda debac dacfbe | fcbega ebadc eba cafdeb
cefgad bdcef acdbfe edbgfc dae beaf bdacefg ea becda bgcda | gdacef adbefc bcgad dceafb
dfbaecg eagfd cf acdf bcgea bcfdge efc dacfge efacg gbadfe | fc fce fecdbg caefgd
afec daebgf dfgcab fcgeabd gef afcgb dcgbe ef gaecbf fecgb | fe cgfab debgfa fgceab
cgafde afbgdce bgafc gabcfd bgdf badgc gf aecdgb ecabf gfc | acgfb gfdb cagdef fcg
fdgec bgcad bfec gbefdc dbf gfdcea fcbgaed bf bfgdea gfdcb | ebcf dbcgf dbf bfcgd
dfceb cdaf bdfage afebc bgfdec fa gbcfdae fea gbeca faecbd | fcgebd fbgaed afdc fa
fgcaeb fcag fa bdace efbcg gdfbaec fab dfgbec abfce fabdge | gcedbf cefgdb ebcdgf efdgba
afegdc fegdbc gfeab cdfb dcegba db bde degfc bafcedg dgfeb | gabcefd cgdbfe bde afgbe
dg gbd adgfcb cfeagb bcfag bcgfd gdaf cbfed gcfaedb ecabdg | dfbgc dg cdfbe dbgfc
cebgfa gcadfeb afcdeb dagfb facdg adbfge bdf db egdb ebfag | dbgfea db bgdefca dcfabe
adbf fgd bcegadf cgfead egbfd bgeda bdceag bgfce fd aegbdf | gedabcf fgbde cbegf cdfgea
ga cgbfd decba gaecfb dfbcga cbdgfe cbdegfa fgad agcbd gab | dagf egfcab bgcda cdfbag
egbfa geca fabcg edfba fge fdcagb cgebfa dcefgb bgdface eg | egafb fabeg fbade aefbg
egcad fadbge fbgd faebg acdbfe edabg bafcgde dba db fecbag | dcgae cbeagdf dacbfe db
ad dcbag cegdabf cgbea feacgd adeb debcga acd agbcef dfbcg | dagcb aegbc cad dgfcb
cebad cfadgbe ecd gdcbae cage cgdbef ce cgdba gcafdb adebf | adecb cfgdab cedbgf daecb
fagceb cbdef cabgfd gadbc ae dfcgeba gcebad bae aegd abdce | abe bae bae gead
efgcab eagdf de ead bfde cdgabfe ebfdag fbeag agedbc gfdac | fcgad eda dgfac eda
gfbeadc cgeafb gdecf bcedgf dfgca cdagef bgafd afc ca cdae | fecgad dfgce cfebga gdfba
fc egfbcda dfc degfca fgdbc dafbg febc dcebg cebgfd ecbagd | eagdcf efcb agbfd bfecdga
db acegb fdbegac dgefa gfcdeb egadbc cdba bde geabd becfag | dbfeacg adcebg cgedab decfbga
ecg acfgde cedb dfecbg gcfdba ec cdbgf cfebg efdbcag fegba | ecbd aedcfg cgfbe gec
fgcadeb ecfagd egfda cd cdf edac fecdg fagdeb gfdbca gcefb | dfgea adgebf dbfgeca cfagbed
cfgedb fgdba cgdef edgfa ea fbaegc age decgaf aced gbedafc | aecdgf dfbag aced dfecbg
de agebc bcdgf fagbec adbegc cbged daec gdefacb deb gdfeba | gdbace aebgc begfad adcbfeg
fdeg cfbgda dcaef dceab gdefac dcf cgafe begdcfa cfeabg df | fcd gdabfc bgefac egcaf
efgbd cgfbe gcb egabcdf debfag cg cgdbfa bceaf cdge degfcb | bfegad cgb gebdfc decg
aefbd bfaec bdgcaf dgeb de fgceabd fgaedc egbdfa badgf fed | bgafde fbaed gdfab gbed
bcdea defagbc fdce cbfade fagbd egcfab cf adgebc cbf dfbca | gbadf dcef dcefab gbcfae
abdc cb bgc bacfeg fabgd cfdeg fcdbg gcdebfa dgaebf dgbfac | gbdcf fcbadg cbg ebagfd
bfgca gfbadce dbcag ecabf cfgead fcg gf edabcf fbge afgbce | bgcda cdgba gf bfcgaed
afgbde cfdgb afbcge gbfec ec cfe dgface gfbae fcagbed beca | cbgfd fdcbg gadcef cbdgf
bfdga gaed dbagfe cgdbef edfba bcaef de gbeadcf gdfacb bed | ed aegbfd adbfgce de
adcb ecgafd ba abf bfedca gdbfae edcaf bgaefdc fcbeg fbeca | efdcga ecgbf gcefb dbeafcg
ac bdecf bac daegb bdegca bcefga gacd febdgac abdgef badec | cgda cagd bgaefd dagefb
gcd ebcd cgfbade dabgfc gbdcfe fdcge gceabf dc gfead ebfcg | gfdbce baefcg dceb fcebg
ceg cfgae facbde ge gcfba bcdfega edacf fcgedb dage cdegfa | dafce ge cdfae fbdeca
decgf fadeg fgaced febda eag fagc ag bgadec fegbdc bafecdg | afdeb badfe aecfgd adefg
da bdeca fdgbce afdbegc efbac gacedb fbdcga acd cdegb gdea | gdea facbe cfeab bedca
ebagdc cdaefg cebfg fadg gd ecgfd dge afedc ebadcf dfbcage | eacdf dagf cgfbe ebfcg
fdbcea ag fag fegdba ecagfd bdgcf afecd afgdc cgae efgabdc | fdaebcg caeg cfgda dgfbc
ea cabgde acbgfe cefbgda acde edbcg aeb ebfgcd dfgab aebgd | cafbge dgfab cdgbe deca
acfd ebgfcad fecbgd dcgabe ca eagfc eac gefab gfdce cgfdae | cgaebd fcad geafc egdacf
fdecab bf fdcb egdaf cgadefb edacgb ceadb daebf afegbc efb | dfebca cedbaf ebfcga dfecab
badef fbedag daebcgf bgcfa dacgef cfadeb dac dcbaf dcbe cd | afcbd dbec cebdafg bacdf
fagedb acbge fceabg cegfb bagcde aecf cfbgd aegdcbf efb fe | bdfaeg fe febagc bceag
efagd dfacg fgcb dgc cefbad cgabde cadfgb dbafecg cdbaf gc | caebdf bcaedg afgde dfcga
egcbf gbdafe fd edf gfecd gcbdae aecdg fgdcea gacdbef cfad | cfbeg cedga fadc facd
bdfceg acd dfbce bfdag ac adcfb daefcb egadcf cbae edfabcg | dbeacf fadbg abecdf bedcf
bcf badcf ecdaf eadgbcf abgf defcbg bf ebgcda bcgda acbfdg | fcb decfa fcb facbgd
da cda adceg bead abgcfed ceagdb gcbed cfgae agdbfc dfbegc | fgdbec cdgfab gebadfc fgcae
gbaecf debfg dbaceg badc eagdb ab abfegdc dcgea cdefag bga | ab cedbafg afcged cgdae
dacfbge dafbc baegdc fagbde dacgb fbcg bdfcga fb abf fdace | acegdb ecfad badfc cadfgb
acbgf gadefb cd egcfad bedc cad cadbg cagbdfe gdeba bdgaec | gceafd gbfac egfabd dcbe
fdbgcae feacgd gcdfe cgdefb gabfe defgb dgb db caegdb dfcb | cgfde cdebga cgdaef gedcaf
ae gacbe facbge cbdefa eca acfdbg afbgc gecbd gcaebfd agfe | ebafgc fgae bcaeg ecgdb
bfdceg badecfg bgefda ba bfa cbda fcage cdeabf fbaec efbdc | bcda fba egacf efabgd
gbc bdgce gcbdefa geac cg bedca dfbcea dgcabe afdcgb gedbf | dfbcea fcdbea gc dfabec
becdf gaedcb cgedaf aegcf fagcdeb gfab gefabc cebfa bca ab | ab gaebfc dceagb fcbdaeg
eagbc acfdge db gfadc fdgb fbagcd dba dcagb gecfbad efbdac | fgbd cgdeaf cdgaebf eagcdf
ga eafg adbge gabdecf cbade bdgfea afgbcd gfbde gab cgedfb | gaef cabed fbgdae agb
efabc cdeaf dgcfa ecbafg ed dagfbe bfadec egdbfac cedb efd | efd bfeca bdcfae de
bagf fb cfeba gcbade cgaeb adfce befgcd cfb defabcg gcfaeb | daecgb bgeca egcab febdacg
dfceg gfcedb bdfea gb bfedg cgdb afgebcd fgdace cbfgea fbg | gb dcbg bedfa gfacbe
gecfab dacgf cfbgdae afdcbg afde cea gcebd fgecad gcdae ea | edacg ea ecafgd gacbef
ag afg bgcdef abfec begdf gadfbce bfgae egbafd egda gadcbf | gafdeb ga bafec dcgbafe
cgadf cegdbf egaf dga efcadbg dfcge ag cabdf eagfcd cegdba | bcafd gdcfbea cdbaf ag
dcbge fdgabc cegba aegfc gfebdc ecfdbga aedb cgebad ab bga | ba aebd bgaec cdbeg
cdg fgdb adfecb gdabfc cagfd fbadc febcdag cdebga geafc dg | gd deabfgc fbadgc fcbdae
debgac fceadb eg gbcfeda gfabde efgd gfbac feadb gbe baegf | baedf edgf cabdeg befdca
cf bgcfe cfg cdgabe cbdf dcfegba bgafe cdefga gbecd edbgcf | dbcf fcbeg cbdf eagbdc
cbefag gbe agec cbgfdea gdbfa facbed dcebgf eg eafbc ebafg | baefgc bdfeca eacdgbf egac
gfd bfgec dfeagbc fedgbc fd cdbf fbeagc efbdg ecgadf daegb | dgf dgf ebdcagf eagbd
fcedbg bcde be fgbecda bfe fadecg edgbaf gcdef becfg fbagc | efdcgb bfgead ecbd fcedg
fbdgae gefabdc bfgdca gbf fcabed cafbg bcdaf gcbd gb agfec | acgdfb abgfdc bfg fcaeg
cfbegad gdfcb bfgde bcdegf egcb bc adcfg gadbfe beafdc cbd | fgadc adecbf gdbefc gbdfe
abgcf ecabdgf dba acgdfb gfebd dfac adbgec da afgdb cbaefg | fbagd dbegf begdf defgb
bdecfag ef bcefda adgce feagbc gbef gfcae fcgab afe fdabcg | cgfeab cfgea bdefca afe
dg cbgeda bgdfa egfd dgb gebadfc febcda gcbaf deabf gaebdf | bdfgcae afgcb dgb bceadfg
cfagedb eacgd baecfd cbafd ef eaf bdfe fgbcad dface febacg | afe fea fdcaeb cedga
fdageb egbcf ec ceb dgcbf gfeba fegcab acef bgaecd cebadgf | bec dgafeb faebg fcbge
agecbfd fcd gbedac dbcfag dfacg df gbcda fcaeg febacd dfgb | dcf gcfea acegf gdabfc
dafebc gbfa agdfc fbcgad fgceadb cdbfg bf bfd adgfec bdcge | fb adbfce feacdbg gafdc
caebgd bgcf gabef bf agbec abfcged bgeacf ebf edfag cfdeba | gaebc fdega ecgba egdfa
deba eb bfe bfaedc ebfdc cgdfae gdcafbe cbeagf bgdcf dacfe | gefcab gbcaefd fbgcd bade
aefcbgd afcde cea aefcgd dgefba efagd ca cagf gcdabe edcfb | adfgbe fgead abfged afgde
cadge fbagec ag ebcdgfa dagf afedc age ecdabf cbdeg gcfdea | eag cafde ega gfacbe
cbgefda acd afgdeb dc fdgab dcbfae gdbc cdbgaf acfeg adcfg | fgdac efdgba dfcag efbgcad
cegad bfgcd baegfc facgd aebgdc af fag feda edafcg cgfbdae | af agdfc gbdafec gfcda
aecgdf ecgfb bfdea cfbaged dgbfce cdf gdcb dc bcdfe aegfbc | dcf gabcef ebcgf fdc
bcafe bfcdea febga ac cfa cdeagf dabc cfdaegb cfedb cfgebd | bedfc dbfgce dcfeb egfba
cgfedb afcb fdc fc bdgcea gacdb gedaf ceafbgd cfgda adcgbf | cgadb cafb dcf adfeg
ebcf def cgaedbf becad bagfd egdcab fgaecd ecfdba ef dfbae | eabfd becf adcgfe gbdfa
gcfabe gcabe dfgca beagdf fbg abfgc bfce bedcag fb fbcagde | bgcae bfce fb bgfeda
dca ebfdacg cgbd gabfde cgfad gadbcf cfeabd fgeac bgdaf cd | cdbg cad dac cd
ebfgadc efgbad bdfceg cbdfg gecb bfedc fgb gb dafcg fedbac | fbg fbg cgeb gebc
ecadfb fdgceba gdebac dea fegdc feagcb ebafc fadce da fabd | bfcega cbaedg cbdeagf bafec
dbf fdaceb cdgefa bf febgacd aefb fdbca cdefbg dcagb edcaf | bacdf dfacb cbfeda aegcdf
gdbef bae edbfcg bfcag agde gebaf gaebfdc cfdabe afdebg ae | defbag afdceb gebfa agbfed
edabf dgbcf bce afecgb degc dbfec bfgcaed ce bgdcef cdfbag | gedc cbfed dfbgc cdeg
bdcfga fag dgafc fg dacbf bdafec cfbg fabdgec eabdfg eagcd | debcaf eacdg geabfd gbefad
cgfda badfc ba gcfdba acfbdeg bcga ebfdag faegcd abd dcfbe | afcdbg acbg ecdfb bdfac
bcdae febgc egdbafc fd gcfd bdefc bcedgf fbdega fde fabegc | dfbgec efcabdg cfbge gdeafb
bfedacg agfdec deg gd decbf ebgcd eadgbc gbfeca bceag gbad | gd ceagb gd gdcafe
acbgd dbfceg cegfdab dbaegc aebcg ecb be dcbgaf egcfa eabd | adeb bec begcdf gfeac
gda debfa gdfe gd cfdgbae bdagec badgfe bgdaf cbdefa fcabg | geabdf abefgd dag ebdaf
febgcd cdaegf bf fabge edafbgc gfaedb baegc ebf fdage fabd | dgecaf badefg geafd dfeacg
adegfb cbgefda dcag agbfdc gbcfa gadfb bfecg ac acdfbe cba | bfgca facgb fgcba ecfdagb
adcf fbecdga dbeagf ac eca gefdac edcag cfbeag edgaf cgebd | dcfa cadfge adegc gcaed
acbdgf gaecfb ad cbdfaeg gebfa gcbed efda gad baegd afedbg | gbfea aegbd adg da
da abd dbgfc dgca gadbf bcgedaf dfbacg fbeadc bfecdg gabef | cedbagf dfcbg gbdacf gcbfd
agcdf cbfgd da dacb cagfe abgdfc aedfbg agd edcbgfa fegcdb | da ecfag aegbdf adgcbf
cd aegdb acfbe bgdc ebacd dbfgea feacdgb agfdce dce dbceag | acdegb gbdc gacdfe dcbg
abc deacbg aecf cgafb dcbgf cgfbae gbaef ca geabdf gcbafde | cgbfd fcea abfeg feca
eagcb edacgfb abfegd abedf aefdcb gfda dcbfge gbafe fg gfb | cbfade acdebf gdfceb bgf
dgcab aedgb gbdcfae acbe beg gebfdc gdbcfa fdage dceabg be | gcedab baegcd bdega beadg
gd dfcgea afdgeb cdfae befacd beagc ged daegc afebdcg cdfg | cdega dcefab gfaebd ebgac
gfcebad gfeca bdcae fbeg cbgafd bg dcagef gab gacbe fabgce | ecbad abg agecf bg
fegdc bdag gbedac dcfeba gfeabc ebfgdac gedac ga ceadb cag | fecbag ebdcaf bfcega aegdc
deabcf dcfa cd ebgfda ecabg aecbd cegfbad dbc cgfedb faebd | gdcbfe cbd befad dcebfg
gedcab bagdfe bf aecdf begf aefbd dbf eabdgcf bfdagc eagdb | fdbea fb cedfa gafdbe
cgfd afecg cedgfa eabcd aefgcb afdgceb dfa fd eafcd debfga | afbgec gadebf fdcg acfed
cdagbe agefb fedabc fagcb gfebdac fgde baegd fe eadbfg feb | gebfa aecbfd fe bedag
adcfb bdcga df daf gdabfe cafdbe cbgfae decf becfa cbgadfe | gdbfcea fgebad fad bdacg
dcgef agc cfbadg ga afgec bcaefd efcba abeg cdeagbf aecbfg | dcfge fbgcae bdgfac fcgde
adcge gdcbaf bad cgdeaf bced abfge dgaeb db aedbgc ebdafgc | acebgd bad bad bdaeg
bgd adfcge gdacb fadb bd degfabc bcaeg dcfag gefdbc gbdafc | bceag badgc db cfdgbe
bdf cbadef ecafd bfacdg bd cbde baefd afcdeg ebgaf edagcbf | gdbcefa dcagfb bfaed dgacfe
cbdaf efbd ef afbec caefgd dagbecf gcadbf cbgea dbeacf aef | afbdc cgfdae caebg adgecf
gbfec ed fgebdc defacgb deb gedc cfebd fedbga cabdf abcefg | gedbfa dfbegac bgcef cbfed
dgc aedcg aedcf gd acegdfb cageb edgb dgcafb cbegfa ceabdg | egbd beacgfd aecfbg gd
abf gdbaef abgfc bf gcafe bdagc dbcagf cadbge bdfcgae fbdc | gfcdab fbgca adbegc cfbd
becfdga eac acedf cgbeda gafdec fabcd egfda ecfg dgaefb ce | cfead afdec gafed bfcda
bdgceaf febg bfacdg feacb gaebfc aebdc ef cfbga facegd fec | bcfga ecf cfbea acfged
baf geacf ab cfdebga cfbgde fgcbd gfbdea dbac gcfab adbcfg | bcdegf bgcdfa dgbfca gfcae
cd ebgcf ebdc dagbf fbgced fgecab cgd fedagc fbcgd fgecbad | fbcge bdafg cfdebga cbed
dfbcag geafc agdec da gad dgecb cgbfae faed edafgc adcgfeb | cagefbd dfbgca gdceb edcga
dfegac aegbf cg ceg agceb bafgde cebda fgbc cebgaf aedbgfc | bfcg efcbag ceafbg fbage
acdfg egd fcge fecdga ecbfgad eg aedcb eadcg gfebad adcfgb | ceabd afdegc aecdg gfbaed
fcbadg faebdc ga edga fcegb geadbf gefab bafde afg dcegbfa | fdceab bfgec fag cgefb
fbge bfeacg edabc dgbfca egdacf beacg gae fceabgd ge fcabg | aebgc abefgc bgef gcafb
cbe fedgb aedc ecbfga ec dabgc bfegdca degbc cgafbd bdeagc | fbedg fcbaedg dgcbe bce
gbdc cb edcfa bagfd agfedbc agfbde dfcab cfb gebafc cagdbf | bcf afgdb dbcfgae cb
bgdae fbagde cegdbfa aegfb fb dbfe gbfdca ecdabg fgb agecf | gadeb bgfade fcbaedg gabed
bfacdg ebcfda cgdfeb edbfgca feadg cfa gabc cgdaf ca cfbdg | ebgfdc bafgcd fgade afc
cgedba abcfge ade fgdbae edgaf egbaf edfabcg bfde ed gcadf | cfdga gaedfb adegcb fgecab
fbdcea bgdcf abfcgd gcab dcgbefa dafcb afbgde fgedc gdb bg | efcabd bcgdf badegcf acdfgb
ebdf dcafgb afdecg ebgca adbfg fe efg bcfdage eabfg agbfde | agcdfb badgf geadfc abefgd
daebc bedcfa def eacfg eafdcbg bcdf edgabc df dfcea gaedfb | fecadb gedbfa dcbea egbfad
gf gdcf cdabf bceadfg dfcgba cbagfe gdeba fbdag gfa dbefac | gedab cfgabe cfadb gbdaf
ced edcgabf dgfceb cdbg fbceag daefg ecdfg cd cfbge cabfed | ebdacf dec dce dacbegf

47
2021/08/prog.py Normal file
View File

@ -0,0 +1,47 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
ret = []
for line in f.readlines():
parts = line.strip().split('|')
ret.append({
"ref": parts[0].strip().split(' '),
"out": parts[1].strip().split(' ')
})
return ret
def result(inp, part = 1):
res = 0;
if part == 1:
for data in inp:
for s in data["out"]:
verbose(s)
if len(s) in [2, 3, 4, 7]:
res += 1
else:
for data in inp:
for s in data["ref"]:
s = list(s)
l = len(s)
if l == 2:
one = s[:]
elif l == 3:
seven = s[:]
elif l == 4:
four = s[:]
elif l == 7:
eight = s[:]
a = list(filter(lambda x: x not in one, seven))[0]
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 1))

1
2021/08/sample_p1 Normal file
View File

@ -0,0 +1 @@
acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | cdfeb fcadb cdfeb cdbaf

10
2021/08/sample_p2 Normal file
View File

@ -0,0 +1,10 @@
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce

10
2021/08/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
# def test_part1(self):
# self.assertEqual(result(get_input(sample = True)), 26)
def test_part2(self):
self.assertEqual(result(get_input(sample = True, part = 1), part = 2), "5353")

100
2021/09/input Normal file
View File

@ -0,0 +1,100 @@
3566789567953212679875689976651013679329876404568999884568910249798689921989789990134578923557899767
2675895456894334598764999865432124567919995323789498765779991998654578899766678981245678912346789656
1234996345789445679989899976543534678998999464569329876899989897643659789954569876456899101237891235
0125679234579659789998789988754755889767898965678912987998976799532345689823678986567984352346932996
2336798945689867894987679798768887998654967899889923498987654678990167899764789998988975443457899889
3578987999795978932976589659879998999543456799999894989998543457789278999876799989699876595667989679
4569876788954399999765479645990239998754899899998789878987632345678989998998999876543997989879876568
5879854567894123989897568924921678919995799998999699869865421234589199997829899998732109878997654347
6998642458963239876998779219793599939876789397689569654997642345691019875215689349883319768998765656
8999843579654569765789899998689978899997899498534458932398543456789229764303478959765498757889876767
9999954678975878974567989876568356789249988987621267891397686567898996543212367899889987645678988978
9989975679986989893459878976421248993149877896532356953998789689946987755325456789998766436359999999
8878989899998998782398967895310237789239966987646457969869898790123499869456567896987754321269898943
7567892999889896531297656789431545678998755398758568979854949932334931998979878945796543210198787892
6454693498766789320198967998698656899876534239878978998763238995449892397999989323987695423239676890
4343989987655996431239998949898768998764321012989989679894346789598789986897993212398986734598545789
4212467986434897545356999235979879899965432124994394567985456897679659875656899424999997865697434679
4101347897323789657467892123467989799877656734789212378976569998796549864345678949898998986986523459
3212356789595678998979999994999995678998867645678934989298678999987659764234567898757999297987534678
4534598899989789999597898789878954579899998756889899891029789995499769872125679999545789398997645689
5645678978978999897456987678969643499798789887998789789939899989998998761016989987678995499998756997
9896789654769999785349876513457965987689678998997675689899999969877899843127898898789329986899987896
5998996543457789654298765425578976798896567899876534996789998753766797654238987649899998795789898965
4699764532345678979129986634989498899975489986987329894345987642345989765649898434999876534679799234
2987643210156789998934899856892349987684349865696498789234596521235678996756789646798765423235678965
0198654321789898997896798768950234998543298764987987676995789432345989987897999859987654210189899876
1239968645678987986897899978931299897654399543499876545789997646559891098998964998999766323568998998
5349898757989976545789934599892989789775987632989765434599898968698789989799765987899878545679357989
7498789868998988637996549989789878678989898321976653223476789979899678975699879976678989857790239878
9987668999987694329689998879679765457899765493495431012345991989998567994989998104589099767989998765
9898556789876542104579897657567931266789879989987654223457892499876456789879876323679239899879899654
8767347994987969223456789543459892345899998779898654336567954931964345698767965434589345999768698923
7643245893299898999968897651669789456789987667799765559698969899986556789656987675689489987656567912
9844156789349767987899998769898679667999876545687986798989999768987687896546798989797679876543458901
9921078895497659876778999899987568978910987632456998987678989656798798998634569999898989987652345892
8762135996569443124567899989876467899999798321269899976567878943899999798765678934999893298793456789
9854345789998321012456998769765326798987654210198787898434569942996987659886789923598789109654567996
8765656899876532126567899849954204567899965321987656789213467899785698543997896899976678998798778935
9877897987987673234878912998765323478989896432398767896323456997654987685798945698964567929899899921
6998998976898998549999899899976534889875796563569878975434567896543299876899434997853598919910979892
4599659985449987678945798789987645678964897678978989876545678976431012997965429876212989998532356789
6976545976232398789432987679898768789985679989999491987657789998679193999986210995304878987654898991
9898679984101239894320976545789879991976899999789210199879997899798979893297399873213467898785789990
9789798643212449965449865434599989210987999897698931249995676789987668789198989965325679949896899989
8698987654323498979567997323478994391298987653567992398764545898976555678949979876566789923987989767
7577898765434987698989986510567895989999989742455689999973136957965434599129864987898899812498977946
4346569986565996567899965432456999979899976541234567893492012349994325989239753498999975701469765435
3265455697679875456899876563567898767789876420125789932987324598989202678998542349899974212359889576
2101234998798754347689989675678987645698765431345678921986434987578914568987321235799865343456998988
3212649899899654236578998799789798534579876542767899510397675996467925679965430124678976659767987899
5434598799987632125467899899897654325678998659878996421298789894348897789876576434679989898979876789
6549987679876545012345999998989865456789999778989987692349898789256789896987797678999899987899765466
7698896567987652123656789977678976567898789999097898989656989698967897995498949899878789875987654355
9987623456799743245778898867545987878998678789156989878969768456998975789349421956965697654599776234
8976512346987654356989987654434699989697547679345976967899654345789654248996532349876789523498765455
7654401467999767467893398763123498798798534568959875656987865257899732056789945656987894312349876878
8743212378999899879932109854012998679987323578998764345976772136678943167899896767898954201956987889
9854434456799975989799349754129876598765435789999879109865321024599955389998797898949969319899998999
8766789578999654394698959843298765439989546999899998913975453245689867899989689999439878498678999678
9898997679998979213997899654349654323498757898789997929989964366795978939876579989923989987569897532
9989698789987654339896798765798766437569968935679976798999878479894599123989468767894698675458789421
9876549892398769498765689986789976545879879546989875787899996589965789094997398656789986436358679510
9995434921239898998654787898997698976789989659899774656899987697976799989875234445698954321246578921
9876545690123987987543456799434569989890199898798653245998698976897999877993101234567896210123467892
0998766789439896987652345679323698999979988987649874067893569765798998966789245645798954321234679993
1239977896598765798761457989212997897658767986534964249932469954319987845978966956789765543376896789
3399798999977554569892567894109886997643457954323975957891398765434596534767897887990987754457895992
4987669498765432498773459943298765789432129865434599878910129976545699721456998999321599865598999893
5796442349874321987654767894998654598943019876545689989321234989686987632345679765452469876679999789
9987321298985430199875678999876543497992124989656799997532346898787996543457799996569569987897987678
8998532397654321234989789589987832986889434598779899898653457939998987668568899789998978998946986583
6987545459865439356999892378998543965678945989989959789864579321019198789689947679876799999439875432
4398756767987898967899943469998799864699659875697943679875689432329099898795433597997899988921994321
9239767898998987898998764598799986543789769864756892467988789553458987969893212345698998777899876434
8959879949799896999879876987697897674678998752245791345799899964567996546954323456789999656789989645
7899989234698785878965998996546998865679219541024689859892999895679754323598435697999898743234698757
6988995345987654667894319998434869986789997432123499767891298789798765434987646788948799865459789878
5567976986896543456796101989322646987999876543234578979910989698999876545698757899235689879878999989
3478987897989552367997429878910235698989989654345689989429878567899989856789898910149793999989989994
1567898939878421058789698667921234569875298765468789996567968345689998767998999321998932349995678943
2349899024965434145678999549892345789943129976578898987699854254678999879877898939897890198789789532
3456789139877543234567987623789959898754434987689976498987643123567899998765687998786791987679894321
4569999245999875655789876434567899979876795698990987689999784347889978987644676789675679896578943210
5678968996789987767893987547698997667987896999891298799899895456789767696532345896563498765458964423
6889345989892399889921297658999889543498999889789459898767976577997654595421476789412349876667896569
7891239879901459998910198789998765432129998767678967987656988789986543987533469994201234988778999678
8992398767899998767891239998769876821012987654569989993347899898998664596545678954354345999989998989
9989499956798787656789399797654987732223498753878899982156789987899779997687899765998656789499987899
9879989877998654545999987589543597654334989762657789876234999876789898798998939879879997892349876798
9767678989876543236678998679421999776459875321045678985456789765689987659999123989768789943589865457
9854589996998752134567899798939898997579986432123567996567998754579898767899934598757678998678974345
9943499875689875238989989987898787989789996543456998998679996543466789878979899997644567898789996659
9875679654579954346798776896989655878999999658567899989989989432345994999569787895432456789898789798
6986998963298765497987545945678933356989898767688999879899876561235893212498656799501234568987679987
5699776792129897679986534124569321239879789979799998965789864310126789423987545698912356899976567896
6798645989012998798765421012789432398765678994921987654678986432645678999895435987894467899988678945
7894534568999129899876532127689943498754567893210199875789987844576789988757329875789578967899989234
8983213345678934987987844234567895976623456895332349876797898655687899876532012964678999356976590123
9876501235799999765698977346788999875412346896546456997896919798798954987653329853568920239876321234
8765432456789987543569765457899998765323467987656897998987909899899865699876598764689321298765432345

81
2021/09/prog.py Normal file
View File

@ -0,0 +1,81 @@
import math
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [[int(c) for c in line.strip()] for line in f.readlines()]
def result(inp, part = 1):
res = 0;
width = len(inp[0])
height = len(inp)
lowest_h = [0 for _ in range(height)]
lowest_v = [0 for _ in range(height)]
lowest = [0 for _ in range(height)]
# get lowest in horizontal
for y, row in enumerate(inp):
for x, cell in enumerate(row):
if (x == 0 and cell < row[x+1]) \
or (x == width - 1 and cell < row[x-1]) \
or (cell < row[x-1] and cell < row[x+1]):
lowest_h[y] |= 1 << (width - x)
# get lowest in vertical
for x in range(width):
for y in range(height):
row = inp[y]
cell = row[x]
if (y == 0 and cell < inp[y+1][x]) \
or (y == height - 1 and cell < inp[y-1][x]) \
or (cell < inp[y-1][x] and cell < inp[y+1][x]):
lowest_v[y] |= 1 << (width - x)
# combine both lowests and get the overall lowests
for y in range(height):
lowest[y] = lowest_h[y] & lowest_v[y]
lowest_points = []
for y, row in enumerate(inp):
for x, cell in enumerate(row):
if lowest[y] >> (width - x) & 1 == 1:
if part == 1:
res += cell + 1
else:
lowest_points.append((x, y))
if part == 1:
return res
res = 1
verbose(lowest_points)
basins = []
for point in lowest_points:
queue = [point]
idx = 0
while idx < len(queue):
x, y = queue[idx]
for d in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
if d[0] >= 0 and d[0] < width and d[1] >= 0 and d[1] < height \
and d not in queue and inp[d[1]][d[0]] != 9:
queue.append(d)
idx += 1;
verbose(f"From { point = }, the region is {len(queue)}")
basins.append(len(queue))
basins.sort()
res = math.prod(basins[-3:])
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

5
2021/09/sample_p1 Normal file
View File

@ -0,0 +1,5 @@
2199943210
3987894921
9856789892
8767896789
9899965678

10
2021/09/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 15)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 1134)

106
2021/10/input Normal file
View File

@ -0,0 +1,106 @@
{{[([{{[<{{<[[()()]]((<>())[<>[]])>{{{[]<>}[<>]}<[{}{}][[]{}]>}}<<<<<>()>>((<>())<{}()>)><{{[]()}{()
{<<{({{[<<[<(<<>[]><<>>){<{}()>[{}()]}>]{{[{{}{}}([]())][{[]()>[[][]]]}<(<{}()><<>[]>)>}>>{[(
[[<{<{{{([[{[[{}()]<<>{}>]}{{<(){}>{<>}}{{<><>}{<><>}}}][[<<()[]>(<>())>[(())([]())]>]])<{
{<[([[<<<(<<<<(){}>>{([]<>){[]{}}}><<[()()][{}[]]>[(<><>)[<>]]>>){[<[<()<>>[[]()]]<<()[]>(<>{})>>[(([](
{[<(<<{{[[[[(<{}()>[(){}]){[()()]{<>{}}}]]]]{([(<<[]{}><<>[]>><[{}[]]{()[]}>)])([<({<>[]}({}<>))([()]({}[]))>
(<[{<[{([[(<<<{}<>){[]<>}>(([][])([]()))>[({()[]}<{}<>>)<{{}<>}{(){}}>])(([{{}()}<[]()>]<({}<>)(<>
{[<<((<{([({([()]<()()>)({<>{}}<[][]>)}<[{(){}}](<<>>)>){<[(<>{})]({(){}}<<>{}>)><{<{}()><[]()>}>}
[[([{<<(((((({<>[]}<<>()>))((({}{})<[][]>)({<>()})))[{[[()]{<>[]}]}[(<<><>>{[][]})({<>[]}[{}<>])]])[<{<
(<([[{{<((<<[(<>{})]<[<><>](()[])>>>(<<{[][]}([]()))>)))>}}]])[[[({[(((<([{}<>])[([]{})<()()>]>))(<<[(<><>)<[
{(<([<[[[<<{<<{}[]>>}[{(<><>)[{}<>]]{[[][]]<[]<>>}]>[<[<()[]>[{}()]]<([]<>){<>{}}>>[{{()[]}([])}[[[]]]]
({{<{(<(({[{{<<>()><()<>>}}]}){[{{(({}<>>)}}<{<<{}[]>>}>]})((<((((<><>)[(){}]){<(){}><{}()>}){({(
[(<{((<[{({<[<{}><[][]>]<{[]<>][[]()]>>[[[[]{}]](<{}<>><{}>)]}({{{[]()}[[][]]}[<{}[]>[{}[]]]}{(({}
(((<<[{{{{{{<[<>][<>[]]>)}}}<<[[[[[]{}]<[]{}>](<[]{}>)][(<<>{}>({}()))]]([[{{}{}}[{}<>]]{{[]
([<[<({(({<{[{()[]}][({}[]){<>{}}]}>{{{[[]{}][<>()]}}<(({}){()()})<[()<>][()]>>}}<([({<><>}({}))({()()}[
<[{<[{{<{(<{<(()[]){{}{}}><{[]{}}{{}()}>}<{[[][]][<><>]}<<()}({}())>>><([[[][]](()<>)])>)(<([<[]<>><<>[]>]{
<((({{<<([[<{({}<>)({}<>)}{[<><>][(){}]}>({[[]][()<>]}<([]<>){<><>}>)]][{{{{<>[]}[{}()]}[(()())<[][]>]}{
<([<[[(<(((({[{}[]][[]<>]}<([][])<[]{}>>){[(()())({}{})](<<>{}>)})))))[{[({[[{{}{}}({}())]][
([[(([{([[<<{[[]()]{[]{}}}{{<>()}}><[<()()>([]<>)]{<(){}>((){})}>>({(<()<>>{()[]})}[(<[][]><[]<>>)]>]{
(({{[([{({{([<()<>>{{}[]}]{({}<>)(()[])})}((<[[]]<{}[]>>{(()<>)[{}<>]})[(<()()>){{()[]}({}()]}])}{(([
[[[(<[<{{([[[({}[])]({(){}}{<>})]<[<{}>]>](([[<>()]{{}{}}]{<<>()>[<>[]]})((({}())<{}()>)<<[]{}>>))]}(<<(
{{([<[<<({({[[{}[]]<[]()>]<{<>{}}[[]<>]>}(([{}{}]{{}<>})[<[][]><[]{}>]))[[[{()[]}{<><>}]]]}<
{([<[<[{[(<{([()()]<[]<>>}<[()()]<()()>>}<{[[]()]<(){}>}([<>[]]{<>()})>>[[((<>[])(<><>))[{{}()}[<>[]]]]<
<{<{((({[[[<{<[]{}><()[]>}>([<<>[]><<>()>]<[<>()][[]<>]>)]]]}(<({<<[(){}]><{[]<>}[{}[]]>><{{[]{}}((){})
[{{{([{[([<[({[]{}})<({}<>){<>{})>][{{<>}<<>()>}<[<>{}]{()[]}>]>{{[[{}<>][<><>]]{<{}()><[][]>}
<<{<<([[([[(<(()<>){[]()}><{<>[]}<<>[]>>)]{<(<[]{}>((){}))([[][]]({}[]))>{[({}[])(<>)]({()()}<<>[]>)}}]
[[([{(([(<[({({}[])<{}[]>})(<(()())(()())>[{<>{}}({}[])])]>[(<<(<>{})>[<{}{}>[<><>]]><<[()()]
[[{{<<((<[{{<(<>[])(())>}}<{{<()<>>}}>]{{<{<[]>(()[])}(<()()><(){}>)>}(<{<{}[]>(<>())}[<()()>{<>()
<<({<<([({((({{}{}}<[]()>)([{}{}])))[<[<<>{}><{}[]>}{((){}){{}{}}}>(<((){})<{}[]>>([<><>](<>[])))]})[
{({<(([[<{{<[<()>][[[]{}]{<>{}}]>[[[()[]]({}<>)][{[][]}{[][]}]]}<<{[()[]][()()]}[({}{})(<>{})]>)}>{[[[{
(({[[<(<[((<(({}[])([]()))<(<>[])[()<>]>>))<[[[{{}[]}<()[]>}]<{{<>[]}{(){}}}>]>]{[{<<<{}<>
<{{<<[(([[([<{[][]}<<>()>><<<>>>])<{((<>{})[[][]])({{}<>}<[]{}>)}(<<{}{}><{}{}>><(<>[])({}<>)>)>]]{<<
{([[<<[({[<(<(()())><{[]()}<()[]>>)<<([][])(()[])>[<[]<>><<>()>]>><{([<>[]]{{}})<{{}[]}{<><>}>}[{{[]}{[]{}
<{[<<(<[[<{(<{{}[]}<[][]>>{[(){}]})([({}{})<{}()>]<<()><{}>>)}>({<{([][])}<{[]{}}<<>{}>>>{(<[]
{{<[[<([[[{[[{<>[]}<(){}>]([<>[]]({}<>])]{<[{}()]{{}[]}>[<{}()>(()[])]}}<{[((){})]}([({}<>){<><>
([<([{<(<[{[{{{}<>}[()<>]}<<()>{[]<>}>]}[[[<<><>><[]<>>]{<{}[]>{<>{}}}]]](<([<<><>><()()>][({}
{{{[{[{([([<[[{}<>]{{}[]}]{<<><>>{{}<>}}>][<<[[]{}][()()]>{{[]}{{}{}}}>{[<[][]>[{}<>]]{(()<>){[]
[<{{<[[[[<{<({(){}}[<><>]>({{}}<<><>>)><({{}<>}[[][]])(([][])(<>{}))>}>]<[(<{[{}()]{()()}}<((){})>
{<<{{<{<({[{{({}())<{}{}>}[[{}[]](<>[])]}<({[][]}<{}<>>)<<<>[]>[{}[]]>>]{{<{[]<>}<[]<>>>{<<>[]>}}}}<
{[(<({([([{[{[<>[]][()()]}<{{}[]}[{}{}]>]}([{{{}<>}([]())}<[<>()](()[])>]{[(()<>)(<><>)]})]<[([{[]
({((<<({{([[<{(){}}<()[]>>(<[]{}>{<>[]})]<{{{}()}(<>[])}[<()[]><{}()>]>]<<[[{}[]]{{}[]}]({()()}[{
{<{<(((<({[<{{(){}}[<><>]}<<{}{}><{}{}>>>]({<[[]{}](<>)>{[[][]]{(){}}}}[{(())<{}[]>}{<<>[]]{()
<<{<({((<[((<<()<>>[<>[]]>{{{}<>}({}<>)})([(()()){[]()}]))[[[<[]<>><<>>]{<<>()><()[]>}]]]>)[(<{(<{{}{}
[({<{{<<{<<{<[<>[]]<()<>>>[({}())([][])]}>>}>>}((([{{<([()[]]{{}()})<<(){}>(<><>)>><(<()()>(<>{}
{[{<<[(<<[(<<{<>[]}{[]{}}>[[[]{}](()())]>)(([(<>[])(<><>)](<[]<>>(()())))[(({}{})([]{}))])](<<({{}()}
<<((({((({<{{{{}{}}[[]()]}([()<>]{<>()})}>}){<{{<(<>())><<()()>[()()]>}}>{[{([()<>]<[]<>>)[<{}(
(([[[{{[{{<<(<{}>{{}()}){{[]()}{<><>}}><[({}[])<<>{}>](<<>{}>[{}[]])>>([<<[]{}>[()<>]>[([]()){(
<({<{<[({{(([{{}()}[[][]]]<{()<>}{<>()}>))<[[({}())({})][{<><>}<[]()>]]{[[<>]{[]{}}]}>}[({{<{}<>>}}
[({{[<[[[[({<{<>[]}{{}{}}>{{{}{}){()[]}}}(<<()<>>{[]{}}>))]({[{<[]()>(<>[])}[(<><>)]]})]]]{<[<(
<<<[({{{[{[(<{()}(()[])><([][])([][])>)({{{}}{<>{}}})]{<[([]<>)[{}()]]((<>())(<><>))>>}{<{{
({([<(([({<<<<[]()>(<>{})><<[]>{<><>}>>{<{<>}{{}()}>({<><>}{[]{}})}>}[<<{(()<>)[{}<>]}([()()]<()()>)>[
[<({{<{<[{{{(((){}))({{}()})}}({[[{}<>]<<>{}>](((){})[[]<>])})}(<<<<()()><[]<>>><<[]{}><()<>>>><<<()<>><<>()
{{(([<<{{({[<{[]}[<>[]]>(<<><>>[[]{}])]{{(<>())({}())}[<[]()>[()[]]]}}[(<[{}()](<>{})><<{}
{<({{([({<<[[[[]{}]{<>()}]{<(){}>{()()}}]>(<{{(){}}({}{})}<<{}()>>>{[<<>()>>{[<>{}]{<>{}}}})>}
{{([<<{<[<([{[{}[]]}(<<>{}>(<>{}))]<<{()()}[<>[]]>{<[]()>([]{})}>)({(<[]><[]>)[<[]<>><{}()>]}(
<((<(({({[(<{[<>[]][{}{}]}{{(){}}}>{{<<>[]>{[]}})){<{<<><>>}<<[]{}>{[][]}>>((<()<>>{()()})([[]()]([]{})))}][[
[<[(<(<{(<<{[[{}<>]]}[{{<>{}}{<><>}}[<[][]>{(){}}]]><{<({}<>){{}[]}>(({}[])({}[])>}[{{{}{}}
<((({{[([<<(<(<>())({}())>({()<>}))({<[][]>([]{})}({(){}}[{}{})))>>])]{<[{[<({(){}}{<>})>{{[{}()](
(<<([<<(<[({(<{}()>[<>[]])[({}{}){<>[]}]}(({()[]}<()()>)([[]()]<(){}>)))(<{{<>{}}[{}[]]}([<>{}][(
<({<(([[((([<<()[]>[<>{}]>](<[(){}]<[]{}>)<[[]][[]<>]>))(([<<><>>{[]{}}]))))[({({<[]()><{}()>}<[
{[{{([(({[{[<[[][]]((){})>[[<><>]([][])]]{([[]{}][<>()]){(()[])[[]<>]}}}[<({{}[]}{<>()})[([]())<{}()>
(<(<[<(<({[[((()()){<><>))[(<>())(()())]][[<<>{}>([]())][{<>()}[<>]]]]}[([{[[]<>]}{<[]{}>}]){<<([]{}){{}[]}>>
[([{(<{[({(([<[][]>[{}<>]]<(<><>)>){({()[]}{()[]})({()}(<>[]))})<[[([]())[(){}]]{[()<>]<[]<>>}]((<<>(
<(<{([{<[{<<[[<>[]]]><<[<>{}][{}{}]>>>([({[]()}<<>()>)[<[]()>]]{<{()<>}>[{[]()}{<>[]}]})}({{[(()[])<[]()
({{<{{[<({{([<()[]><{}<>>]<{[][]}[<><>)>)[<(<>{}){{}()}>(<<>{}>[{}[]])]}<{((()<>)[()()])<((){}){{}{}}>
<{[[{{{[(([<({<><>}{<>()})>({<[]{}>[<><>]})]){<[[[{}[]]{()()}]{[<><>)[{}{}]}]><((([][])){[[]
{[{[[[{[<<{{[[[][]]{{}()}][<<>()>{(){}}}}{{<<>{}>[{}[]]}}}[({<<>[]>{[]{}}}<({}<>)[[]()]>)]>({(<<[]<>>
<[[{(<({<({<([()<>])<{<>[]}{{}()}>>})<([<(<>[])<()()>>(<(){}>[{}[]])>([[{}[]]({})]{{<><>}<<>[]>}))[[{[{}
<{{[[{<(<[((((()<>)<{}[]>)<((){})[(){}]>))][[<[({}<>){()}]<[<>{}]{[][]}>>({[()()][()()]})]]>)>}]<<<(
[<[<{(<{<[(([<[][]>])[((<>()>([][]))[{()}{{}<>}]])({[[{}<>](()())](({}())<()[]>)}<{(<>())[(){}]
[<<[[(([[[({[{()[]}(<>{})]{[{}]<<>()>}}{[{[]<>}{()()}]<([][])>})][{((<<>()>(<>[])){{<><>}<()[]>})<[[{}(
<{<([[[([[{[{{[]<>}<{}<>>}](<{()[]}(<>)>{<{}{}>([]{})})}]<<{{{<>{}}{<>()}}<<<>()>[()[]]>}[{[[]
{[[[([{<([(([[()[]]([][])][[<>()](()<>)]]<<{(){}}[(){}]>[{[]()}(<>)]>)<[[[{}()][()]]<({}{}){<>()}>]([[()()]{
(({<(({[(<(({({}[])({}[]]}([[]()]([]())))[<<()<>>{{}()}>[[()()]]])>)<([[[[{}[]]{<>()}]]({([]())(<>())
<[<{({{<{({<{[{}()]{[]}}<[()<>]<(){}>>>[[<[]{}>{{}<>}]<[[]]<<>[]>>]}<{<[<>()][{}{}]>{[()()][<>]}}>)}{{{[[[[]<
(({{([([{{{[{{{}[]}{<><>}}<{{}}(<>())>][(([]{}){<><>})<<[]<>>[<>()]>]}}{{[([<>{}]<()()>)({(){}})]({(<
<<<<(([(([{[<[(){}]([]<>)>]((([][])({}{}))(([]{})<[]>))}])(({{[{{}()}<[]<>>](({}<>)[<>()])}({{[
{{[<[<[([{(({([]())(<>())}[[[]<>]([]{})])[{<[][]>({}{})}{({}[]){()<>}}])}][{{(<(<><>)([]<>)>([<>()](()())))
[[[(<[<([[{[<<(){}>((){})>{<{}<>>({}())}][<<()>([]<>)>([<>[]]<[]>)]}{{<[<>()]<{}<>>><<()<>>{{}<>}>}<<[[]
[<<(<<({<{{(((()())))<[{()()}(()[])][[()()]]>}[{{(()<>)[[]()]}<<<>{}>{<><>}>}[([()[]]<()()>)(
<<{{{<<{{{<[{<[]()>([][])}<{<>{}}{[]{}}>]([{<>()}({}<>)])>}<<[([{}{}][{}])[{{}<>}(()<>)]][<({}())({}()
[<<<{[{(([<<[{<><>}[[]<>]][([][]){[][]}]>[[{()[]}[{}[]]]({()[]}[{}{}]>]>{<[<[]()><<>{}>]<{()[]}([][])>>}]<{
{{([({<[({{{<{[]<>}{<><>}>[<{}{}>{{}()}]}<<<[]()><<>()>}{(()[])[{}{}]}>}}<<([[[]()]{[]<>}]<(()[])([]{})>)[<((
[{<{{<[[<[{<(([]{})<()<>>)(<[][]><[]()])>[{({}<>){{}()}}({()[]}[(){}])]}]>]]{[<({<{<<><>>}<{(
[[<[(<{[<({[(<{}{}>(()()))]<[<[]<>>[{}()]]<({}())([]())>>})>[([[(({}{}){[][]}){{{}<>}({}{})}]]({<[{}[]][()
([(<[<<(<{((<{()[]}([]{})>(<(){}>)){(({}<>){()[]})<[<>[]]<(){}>>}}}>[{{{[[{}[]]]}((<<>()><{}{}>
({{{[(<({[<{<({}<>){()[]}>[<()<>>(<>{})]}<[<{}()>([]<>)]((<>{})[{}[]])>>({[{{}<>}(<><>)}}{({{}()}<<><>>){[
([[<<{<<[<{(<({}<>)<[]<>>>)[[[{}[]][{}<>]]([()[]](<>()>)]}>][{{[[<<><>>][[{}()]<{}[]>]]{<{()[]}{{
{(<<[(<<({[{<[[]()){(){}}>{[[]{}]<{}{}>}}<{<()>[()()]}[<()()><<><>>]>]<<[<[][]><<>{}>]{{[]
[<({[({{{<[<({[]{}}[[][]])>]>[{{{{<>{}}({}()}}(<[][]>{[]()})}([<<><>><{}{}>])}{[<<{}{}>(()[])><{<
{([[<[({{<(({(()<>){<>{}}}{[<>[]](<>[])}))<[<[<><>]>[([][]){{}()}]]{<(<>())>}>>}[({[{<<>{}>({}[])}<{[]{}
(<<[[[[[<<(({([]()){<>()}}{[{}<>]<<>()>})[{(<>{}){[]()}}]]<<[<[]()>[[][]]]>[<[[]<>]([]{})>{
{[[([({<[{<(({{}()}([]())){{[]()}[(){}]}){[<[]<>>[[]<>]]<(()){<>{}}>}>({((()())({}<>))([()()](
[({<{<{[[{{<<{[]}>{<{}[]>[{}()]}>([<[]()>(())])}}<(((({}())(<><>))))(<[{(){}}([]())][[{}[]][()[]]]>[{{{}()}
[[((([[{<(<<<{{}{}}{()()}>{[[]()]{(){}}}><<(<>())>([<>{}]{<>{}})>>)>[{({{([]{}){<>[]}}{(()
{([{([<({[[[([{}{}]<<>()>)((()())<[]<>>)][<[(){}]<[]()>>[<<><>>]]]<<<({}<>)[()()])<<[]<>><()()
{<(<<{({{([<{[()<>]{()<>}}<[(){}]<{}[]>>>](([<[]>([]())]{([])((){})})((([][])(()<>})[{{}}<(){}>])))}<<((<
([{<{{<{[{<{<{<><>}{{}()}><<[]()>(()[])>}{<(<>())[<>[]]>{{[][]}<()()>}}><<{(()[]){{}()}}>>)(({[[{}
{{(<({<[<([{([()<>]([]()))<<[]{}>[[]{}]]}{<({}<>)(<>[])><<[]{}>[[]()]>}][{{((){})<{}[]>}<(<><>
<({<{[[{[({(<[()[]]{[][]}>{<[]()><()()>>)<{<(){}>((){})}(([]{})({}{}))>}[<({[]<>}([]<>))<({}){<>[]}
([[{(((({{{[<<{}{}>{()()}>({[]<>}[[]()])][{[{}<>]<()()>}([<><>]))}}{({(<[][]>[<><>])}[{[<>()]<[]{}
([{{<[(<([{{(([]())({}[]))}{{(<>())[<>{}]}<(()[])([]())>}}{<{<()>{{}{}}}>(<[{}]<{}{}>><{{}{}}([]{})>)}]){<
{((<{[<<(<([(<{}<>>)]<(<[]{}>{[][]}}[[()()][[]<>]]>){{{[[]{}][<>()]}<((){})(<>())>}{(([]{})<[][]>)[([]())
{({[<{<{[{[<{([]<>)({}<>)}<({}())({}[])>>{{{<>{}}([][])}[<[][]>]}]}((([<<>{}>{<>[]}][<{}{}><()()>])[
{({{(({(<<<[(<<><>><<>[]>)((())<{}<>>)]>{<[<()<>><[]>]{{<><>}[{}[]]}>}>><{[{([{}{}]{<><>})[{
(<{[[({(<{[[(<[]()><<><>})<([]()){[][]}>]{((<>{})[()<>])}]}{[{{<[]<>>{[][]}}[<[]<>><<><>>]}]{{{{
<<(({[[{[<((<[{}{}]{[]()}>{{()[]}<<><>>})([[(){}](<>[])]<<{}[]>[(){}]>))<<{{{}[]}({}{})}(<()<>>[

76
2021/10/prog.py Normal file
View File

@ -0,0 +1,76 @@
from collections import deque
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [line.strip() for line in f.readlines()]
def result(inp, part = 1):
res = 0
opening = ["(","[", "{", "<"]
closing = [">", "}" ,"]", ")"]
pairs = {
"(": ")",
"[": "]",
"{": "}",
"<": ">",
}
points_1 = {
")" : 3,
"]" : 57,
"}" : 1197,
">" : 25137
}
points_2 = {
")" : 1,
"]" : 2,
"}" : 3,
">" : 4
}
tmp_res = []
for line in inp:
stack = deque()
ignore = False
for c in line:
if c in opening:
stack.append(c)
elif c in closing:
op = stack.pop()
if pairs[op] != c:
ignore = True
if part == 1 :
res += points_1[c]
break
if part == 2 and (not ignore) and len(stack) > 0:
tmp = 0
verbose("stack before: ", stack, end="")
while len(stack) > 0:
tmp *= 5
tmp += points_2[pairs[stack.pop()]]
# insert sort
verbose(" = ", tmp)
if len(tmp_res) == 0 or tmp > tmp_res[len(tmp_res) - 1]:
tmp_res.append(tmp)
else:
for i, r in enumerate(tmp_res):
if tmp < r:
tmp_res = tmp_res[:i] + [tmp] + tmp_res[i:]
break
verbose(tmp_res)
if part == 1:
return res
else:
return tmp_res[len(tmp_res)//2]
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

10
2021/10/sample_p1 Normal file
View File

@ -0,0 +1,10 @@
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]

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

@ -0,0 +1,12 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 26397)
self.assertEqual(result(get_input()), 341823)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 288957)

10
2021/11/input Normal file
View File

@ -0,0 +1,10 @@
6318185732
1122687135
5173237676
8754362612
5718474666
8443654137
1247634346
1446514585
6717288267
1727871228

59
2021/11/prog.py Normal file
View File

@ -0,0 +1,59 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [[int(i) for i in line.strip()] for line in f.readlines()]
def result(inp, part = 1, steps = 100, grid = False):
res = 0;
for step in range(1, steps+1 if part == 1 else 2**31 - 1):
# increment each octopus
inp = [[i+1 for i in line] for line in inp]
# get the ones about to flash
queue = []
idx = 0
for y, row in enumerate(inp):
for x, cell in enumerate(row):
if cell > 9:
queue.append((x, y))
while idx < len(queue):
res += 1
x, y = queue[idx]
idx += 1
inp[y][x] = 0
for d in [(x-1, y-1), (x, y-1), (x+1, y-1),
(x-1, y), (x+1, y),
(x-1, y+1), (x, y+1), (x+1, y+1)]:
x1, y1 = d
if x1 < 0 or x1 >= len(inp[0]) or y1 < 0 or y1 >= len(inp):
continue
if d not in queue:
inp[y1][x1] += 1
if inp[y1][x1] > 9:
queue.append(d)
if step in [193, 194, 195]:
verbose(f"{step = }")
verbose(f"{len(queue) = }")
for row in inp:
verbose(str(row))
if part == 2 and len(queue) == len(inp) * len(inp[0]):
return step
verbose(f"{len(queue) = }")
for row in inp:
verbose(str(row))
if grid:
return inp
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

10
2021/11/sample_p1 Normal file
View File

@ -0,0 +1,10 @@
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526

61
2021/11/test.py Normal file
View File

@ -0,0 +1,61 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1_grid(self):
self.assertEqual(result([
[1, 1, 1, 1, 1],
[1, 9, 9, 9, 1],
[1, 9, 1, 9, 1],
[1, 9, 9, 9, 1],
[1, 1, 1, 1, 1],
], grid = True, steps = 1), [
[3, 4, 5, 4, 3],
[4, 0, 0, 0, 4],
[5, 0, 0, 0, 5],
[4, 0, 0, 0, 4],
[3, 4, 5, 4, 3],
])
self.assertEqual(result([
[1, 1, 1, 1, 1],
[1, 9, 9, 9, 1],
[1, 9, 1, 9, 1],
[1, 9, 9, 9, 1],
[1, 1, 1, 1, 1],
], grid = True, steps = 2), [
[4, 5, 6, 5, 4],
[5, 1, 1, 1, 5],
[6, 1, 1, 1, 6],
[5, 1, 1, 1, 5],
[4, 5, 6, 5, 4],
])
def test_part1(self):
self.assertEqual(result([
[1, 1, 1, 1, 1],
[1, 9, 9, 9, 1],
[1, 9, 1, 9, 1],
[1, 9, 9, 9, 1],
[1, 1, 1, 1, 1],
], steps = 1), 9)
self.assertEqual(result([
[1, 1, 1, 1, 1],
[1, 9, 9, 9, 1],
[1, 9, 1, 9, 1],
[1, 9, 9, 9, 1],
[1, 1, 1, 1, 1],
], steps = 2), 9)
self.assertEqual(result(get_input(sample = True), steps = 10), 204)
self.assertEqual(result(get_input(sample = True)), 1656)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 195)

22
2021/12/input Normal file
View File

@ -0,0 +1,22 @@
um-end
pk-um
FE-il
ay-FE
pk-start
end-jt
um-FE
RO-il
xc-ay
il-end
start-EZ
pk-FE
xc-start
jt-FE
EZ-um
pk-xc
xc-EZ
pk-ay
il-ay
jt-EZ
jt-om
pk-EZ

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

@ -0,0 +1,67 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [line.strip() for line in f.readlines()]
def dfs(start, end, I_V, E, visited, path, part):
verbose(f"\t\tvisiting {I_V[start]} ({part = })")
if start == end:
verbose(f"found end")
verbose(f"\t\tpath {list(map(lambda i: I_V[i], path))}")
verbose("\t\t", end = "")
for i, v in enumerate(visited):
if v:
verbose(f"{I_V[i]} visted {v}, ", end = "")
verbose()
return 1
ret = 0
for i, e in enumerate(E[start]):
if e > 0 and visited[i] < part and visited.count(2) <= 2 :
tmp_v = visited[:]
if I_V[i] == I_V[i].lower():
tmp_v[i] += 1
# verbose(f"\tstarting search from {I_V[i]}")
ret += dfs(i, end, I_V, E, tmp_v[:], path + [i], part)
return ret
def result(inp, part = 1):
res = 0;
# construct the graph with an adjacency matrix
V_I = {}
I_V = []
for line in inp:
nodes = line.split('-')
for n in nodes:
if n not in V_I:
V_I[n] = len(I_V)
I_V.append(n)
E = [[0 for _ in range(len(V_I))] for _ in range(len(V_I))]
for line in inp:
nodes = line.split('-')
n1, n2 = V_I[nodes[0]], V_I[nodes[1]]
E[n1][n2] += 1
E[n2][n1] += 1
start = V_I["start"]
verbose(f"{start = }")
end = V_I["end"]
verbose(f"{end = }")
visited = [0] * len(V_I)
visited[start] = 2
res = dfs(start, end, I_V, E, visited, [start], part)
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

7
2021/12/sample_p1 Normal file
View File

@ -0,0 +1,7 @@
start-A
start-b
A-c
A-b
b-d
A-end
b-end

10
2021/12/sample_p2 Normal file
View File

@ -0,0 +1,10 @@
dc-end
HN-start
start-kj
dc-start
dc-HN
LN-dc
HN-end
kj-sa
kj-HN
kj-dc

18
2021/12/sample_p3 Normal file
View File

@ -0,0 +1,18 @@
fs-end
he-DX
fs-he
start-DX
pj-DX
end-zg
zg-sl
zg-pj
pj-he
RW-he
fs-DX
pj-RW
zg-RW
start-pj
he-WI
zg-he
pj-fs
start-RW

18
2021/12/test.py Normal file
View File

@ -0,0 +1,18 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 10)
self.assertEqual(result(get_input(sample = True, part = 2)), 19)
self.assertEqual(result(get_input(sample = True, part = 3)), 226)
def test_sol1(self):
self.assertEqual(result(get_input()), 3497)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 36)
self.assertEqual(result(get_input(sample = True, part = 2), part = 2), 103)
self.assertEqual(result(get_input(sample = True, part = 3), part = 2), 3509)

896
2021/13/input Normal file
View File

@ -0,0 +1,896 @@
94,530
698,875
221,18
1232,443
689,509
1153,225
239,16
1265,275
589,264
594,766
882,159
1245,435
6,686
383,488
497,535
601,353
326,330
1277,509
773,239
331,567
174,43
1047,551
771,358
716,871
1215,346
228,357
703,647
1272,299
363,668
967,248
1145,490
160,194
912,410
227,623
1041,402
811,257
50,505
67,772
211,275
751,38
1078,311
552,590
1280,389
1031,91
102,654
361,590
50,241
1225,445
658,773
1101,844
785,89
244,294
984,564
703,592
430,493
703,131
214,345
922,247
706,35
515,410
724,560
1113,325
735,70
1195,747
244,136
572,92
1285,889
813,227
1245,591
423,38
962,708
489,42
865,687
798,603
271,777
1299,854
55,117
885,182
952,680
1126,99
129,275
69,770
1305,1
65,683
880,204
224,142
1235,151
174,345
1285,827
1263,112
1215,548
50,884
556,805
288,147
167,259
47,434
417,796
609,54
147,79
848,385
1305,451
795,585
569,472
197,649
837,371
306,862
924,863
539,171
1220,414
909,749
1041,191
666,28
716,128
1091,613
927,614
686,120
1200,98
1255,466
161,294
952,438
43,651
445,739
1235,781
217,501
42,371
33,304
386,863
783,575
999,304
412,527
239,591
303,624
622,794
186,572
785,469
1213,712
311,696
459,240
922,43
694,523
107,820
1181,619
1007,624
454,847
607,434
1225,893
393,795
1113,693
430,752
388,549
433,402
115,723
522,376
713,624
801,819
884,145
60,871
823,259
1263,24
124,875
601,725
459,654
1190,19
1113,309
1298,798
1086,817
1231,294
919,551
151,700
539,536
574,449
544,546
604,35
569,422
25,148
1230,781
587,351
915,95
1056,851
1170,630
915,150
1278,100
552,142
132,518
129,537
1265,726
410,316
1285,372
763,57
11,563
1076,348
82,802
977,256
1260,35
470,795
1039,366
388,345
1225,870
1208,240
1016,346
244,758
254,851
244,86
1310,493
567,71
11,115
1230,449
711,565
157,225
856,847
350,583
694,595
1267,651
1115,128
1110,47
1233,333
1208,654
27,333
845,665
539,397
445,687
1041,703
800,607
960,535
288,803
165,294
537,168
186,322
686,680
1099,723
607,302
1101,626
375,593
525,201
609,51
373,207
20,829
157,618
11,854
139,36
1009,596
657,647
410,578
301,521
348,186
69,796
1086,204
771,210
515,833
924,31
1288,359
647,301
949,749
527,127
1207,280
689,23
629,827
661,767
1034,483
785,201
500,851
853,721
1183,220
735,824
437,841
959,624
601,801
1153,669
224,369
741,445
457,721
385,492
1195,397
828,267
1039,152
415,814
785,581
209,50
1153,618
25,827
821,42
271,614
721,264
1038,534
900,561
726,715
1017,593
795,36
197,693
758,240
701,627
557,438
856,47
497,359
426,145
594,128
883,159
1113,203
604,211
925,639
927,329
57,165
807,331
258,535
905,2
745,383
629,789
411,712
348,513
145,159
80,449
412,367
922,269
232,306
415,815
1014,774
382,534
950,324
803,752
243,182
895,416
395,346
246,70
657,695
539,312
455,660
261,815
386,31
47,460
816,194
214,212
599,117
1186,875
621,509
845,682
683,781
415,192
244,600
157,807
599,565
909,348
788,341
102,401
242,199
718,623
962,186
77,674
279,91
884,537
537,339
430,401
547,728
706,57
899,712
233,210
1054,133
195,94
234,800
679,645
845,821
545,877
597,624
560,87
768,72
269,255
723,351
383,329
1208,80
233,236
15,847
704,136
949,593
1243,122
321,451
314,768
1245,640
1243,827
1288,535
1071,430
612,875
1220,480
648,208
758,752
979,623
1071,591
542,212
455,220
89,511
898,367
415,863
686,57
127,212
358,241
937,504
1113,17
851,240
343,752
575,70
366,539
12,798
229,357
694,299
698,75
1260,505
25,522
1089,453
358,438
1150,194
1184,847
801,75
851,128
80,781
1099,275
1179,128
582,704
45,331
38,299
1073,369
1242,670
925,492
259,772
221,5
209,319
1245,683
1179,318
1250,542
261,795
1158,82
161,714
5,1
1207,614
783,569
1205,624
688,794
890,240
375,472
502,68
989,575
428,159
195,766
689,749
547,57
299,113
36,271
1068,3
1263,220
888,588
502,569
917,99
900,578
47,220
1081,357
870,549
237,749
430,849
1195,723
900,310
793,560
741,449
831,476
433,492
1073,322
1086,369
959,270
334,686
1228,362
90,414
507,367
412,871
851,352
70,627
33,509
152,826
539,582
755,175
405,450
507,424
528,47
1165,159
1032,360
1250,871
987,719
932,483
821,600
566,777
724,476
1004,708
937,275
1086,33
1073,145
865,207
1081,327
358,689
525,469
261,192
927,186
0,401
724,334
127,767
917,254
709,93
567,255
361,369
1171,36
527,276
527,679
566,49
726,267
835,200
373,619
771,684
445,851
825,618
465,821
358,217
1263,560
406,115
1200,460
1082,593
485,186
923,485
343,740
426,357
570,891
274,236
355,113
165,376
1081,771
291,226
877,889
917,547
480,569
73,546
782,847
1195,312
1295,847
290,847
55,466
808,549
209,626
870,212
433,876
267,409
1183,773
1226,199
22,359
621,357
229,119
913,348
160,700
206,539
534,19
1041,553
1159,3
979,775
291,312
1113,245
417,301
282,551
1203,389
1029,267
465,229
1006,135
1166,607
1195,110
880,401
570,443
733,333
375,723
137,560
1173,560
303,49
930,210
681,446
209,844
25,746
1086,304
1153,807
1260,389
296,205
821,516
935,723
1082,145
773,339
32,346
1263,782
448,803
853,247
107,389
68,476
420,546
793,334
771,397
694,803
547,389
977,319
1039,565
561,236
559,184
750,87
1145,294
490,621
667,563
661,443
527,220
862,467
1022,91
197,201
171,705
1155,637
704,758
50,35
195,318
882,735
1242,476
662,208
855,212
92,124
248,442
745,572
858,691
1086,861
701,838
348,750
50,145
877,453
102,814
50,859
1241,796
661,127
271,117
68,535
231,548
293,752
440,613
604,859
929,568
256,133
587,515
663,301
920,495
967,198
228,593
691,836
1082,357
835,246
1129,147
768,568
808,180
1203,148
1310,655
258,588
837,819
224,33
490,273
880,690
715,840
401,546
1069,63
542,568
1285,334
880,493
1066,86
1096,345
736,449
258,359
1300,361
724,418
1227,264
609,715
152,549
713,105
373,838
75,113
475,246
1200,796
649,443
552,752
821,294
32,324
766,546
708,658
744,845
272,534
488,638
795,484
53,1
219,515
1113,761
733,561
853,581
949,200
60,493
1228,84
5,893
185,633
209,268
877,18
840,99
331,775
952,653
197,17
480,325
171,854
102,449
937,723
783,851
711,728
209,575
517,334
1029,627
1081,119
504,894
427,159
895,16
181,747
512,603
701,54
266,1
338,740
607,197
155,637
914,588
324,213
55,329
1235,743
169,276
197,877
1104,19
179,470
243,712
602,658
900,92
393,99
410,92
1039,280
1014,680
994,861
927,280
253,301
1233,561
1044,549
485,260
589,470
102,80
507,143
457,581
706,837
509,159
1004,144
415,366
214,281
237,572
112,774
920,399
766,348
324,325
1260,859
607,112
900,802
72,179
830,569
1161,710
373,396
269,639
922,177
714,843
1135,292
333,506
90,480
67,827
1077,210
596,843
443,275
820,273
873,841
1014,438
306,144
479,602
987,327
703,302
552,829
232,311
1257,353
393,264
990,208
12,96
979,719
497,667
1007,270
353,827
947,668
271,708
221,453
102,445
221,402
393,254
1068,199
253,266
231,856
1113,585
731,319
518,584
301,821
923,877
147,815
701,267
1108,203
329,292
425,323
986,213
817,628
1183,682
72,715
256,410
475,200
709,801
564,414
120,19
459,352
949,145
390,399
1044,585
242,695
445,50
1046,399
1044,43
840,200
206,19
82,810
67,351
144,287
304,135
127,575
1126,795
566,397
68,670
624,241
522,518
1260,145
1031,472
244,578
758,829
223,17
321,388
624,568
1086,466
1235,878
793,441
165,742
586,672
564,480
197,203
294,548
1268,371
880,1
629,446
875,67
1145,518
415,519
937,838
1171,858
425,771
242,891
721,303
731,255
82,767
934,310
383,614
994,476
1158,569
22,535
792,534
1115,542
1208,304
1044,814
959,497
738,308
855,220
1043,409
239,303
47,91
611,203
fold along x=655
fold along y=447
fold along x=327
fold along y=223
fold along x=163
fold along y=111
fold along x=81
fold along y=55
fold along x=40
fold along y=27
fold along y=13
fold along y=6

91
2021/13/prog.py Normal file
View File

@ -0,0 +1,91 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
tmp = f.readlines()
coords = []
n = -1
for i, line in enumerate(tmp):
line = line.strip()
if line == "":
n = i+1
break
line = line.split(",")
coords.append((int(line[0]), int(line[1])))
folds = []
for fold in tmp[n:]:
fold = fold[11:]
fold = fold.split("=")
folds.append((fold[0], int(fold[1])))
return {
"coords": set(coords),
"folds": folds
}
def width(l):
m = 0
for x, _ in l:
if m < x:
m = x
return m + 1
def height(l):
m = 0
for _, y in l:
if m < y:
m = y
return m + 1
def print_grid(coords, w, h):
out = [[" " for _ in range(w)] for _ in range(h)]
for x, y in coords:
verbose(f"{x, y = }, {w, h = }")
out[y][x] = '#'
for l in out:
print(''.join(l))
def result(inp, part = 1):
res = 0;
coords = inp["coords"]
w = width(coords)
h = height(coords)
for axis, n in inp["folds"]:
new_coords = []
verbose(f"folding over {axis} = {n}")
# verbose(f"\tbefore {coords = }")
# print_grid(coords, w, h)
for x, y in coords:
nc = (x, y)
verbose(f"\tbefore {nc}")
if axis == "x" and x >= n:
nc = (w - 1 - x, y)
elif axis == "y" and y >= n:
nc = (x, h - 1 - y)
verbose(f"\tafter {nc}")
new_coords.append(nc)
if axis == 'x': w = n
else: h = n
coords = list(set(new_coords))
# verbose(f"\tafter {coords = }")
# print_grid(coords, width(coords), height(coords))
if part == 1:
return len(coords)
print_grid(coords, w, h)
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

21
2021/13/sample_p1 Normal file
View File

@ -0,0 +1,21 @@
6,10
0,14
9,10
0,3
10,4
4,11
6,0
6,12
4,1
0,13
10,12
3,4
3,0
8,4
1,10
2,14
8,10
9,0
fold along y=7
fold along x=5

10
2021/13/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 17)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 0)

102
2021/14/input Normal file
View File

@ -0,0 +1,102 @@
ONSVVHNCFVBHKVPCHCPV
VO -> C
VV -> S
HK -> H
FC -> C
VB -> V
NO -> H
BN -> B
FP -> K
CS -> C
HC -> S
FS -> K
KH -> V
CH -> H
BP -> K
OF -> K
SS -> F
SP -> C
PN -> O
CK -> K
KS -> H
HO -> K
FV -> F
SN -> P
HN -> O
KK -> H
KP -> O
CN -> N
BO -> C
CC -> H
PB -> F
PV -> K
BV -> K
PP -> H
KB -> F
NC -> F
PC -> V
FN -> N
NH -> B
CF -> V
PO -> F
KC -> S
VP -> P
HH -> N
OB -> O
KN -> O
PS -> N
SF -> V
VK -> F
CO -> N
KF -> B
VC -> C
SH -> S
HV -> V
FK -> O
NV -> N
SC -> O
BK -> F
BB -> K
HF -> K
OC -> O
KO -> V
OS -> P
FF -> O
PH -> F
FB -> O
NN -> C
NK -> C
HP -> B
PF -> H
PK -> C
NP -> O
NS -> V
CV -> O
VH -> C
OP -> N
SO -> O
SK -> H
SV -> O
NF -> H
BS -> K
BH -> O
VN -> S
HB -> O
OH -> K
CB -> B
BC -> S
OV -> F
BF -> P
OO -> F
HS -> H
ON -> P
NB -> F
CP -> S
SB -> V
VF -> C
OK -> O
FH -> H
KV -> S
FO -> C
VS -> B

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

@ -0,0 +1,69 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
tmp = f.readlines()
ret = {"start": tmp[0].strip(), "alphabet": {}, "rules": {}}
for line in tmp[2:]:
line = line.strip().split(" -> ")
l, r = line[0], line[1]
for c in l:
ret["alphabet"][c] = 0
ret["alphabet"][r] = 0
ret["rules"][l] = r
return ret
def result(inp, part = 1, steps = 10, ret_len = False, ret_state = False):
res = 0;
alph = inp["alphabet"]
rules = inp["rules"]
state = {k: 0 for k in rules.keys()}
s = inp["start"]
for c in s:
alph[c] += 1
for i, c in enumerate(s[:-1]):
state[s[i] + s[i+1]] += 1
# for k, v in state.items():
# if v > 0:
# verbose(k)
for _ in range(steps):
verbose(f"step {_}")
if _ == 3:
verbose(sum(alph.values()))
for k, v in state.items():
if v > 0:
verbose(k, v)
new_state = {k: 0 for k in rules.keys()}
for k, v in state.items():
if v > 0:
r = rules[k]
new_state[k[0] + r] += v
new_state[r + k[1]] += v
verbose(f"\tadding {r}")
alph[r] += v
state = new_state.copy()
verbose(f"{len(alph) = }")
res = max(alph.values())- min(alph.values())
if ret_state:
return {k: v for k, v in state.items() if v > 0}
if ret_len:
return sum(alph.values())
return res
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2, steps = 40))

18
2021/14/sample_p1 Normal file
View File

@ -0,0 +1,18 @@
NNCB
CH -> B
HH -> N
CB -> H
NH -> C
HB -> C
HC -> B
HN -> C
NN -> C
BH -> H
NC -> B
NB -> B
BN -> B
BB -> N
BC -> B
CC -> N
CN -> C

32
2021/14/test.py Normal file
View File

@ -0,0 +1,32 @@
from prog import *
import unittest
def res(s):
ret = {}
for i in range(len(s[:-1])):
sub = s[i] + s[i+1]
if sub in ret:
ret[sub] += 1
else:
ret[sub] = 1
return ret
class Tests(unittest.TestCase):
def test_state(self):
self.assertEqual(result(get_input(sample = True), steps = 1, ret_state = True), res("NCNBCHB"))
self.assertEqual(result(get_input(sample = True), steps = 2, ret_state = True), res("NBCCNBBBCBHCB"))
self.assertEqual(result(get_input(sample = True), steps = 3, ret_state = True), res("NBBBCNCCNBBNBNBBCHBHHBCHB"))
self.assertEqual(result(get_input(sample = True), steps = 4, ret_state = True), res("NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB"))
def test_len(self):
self.assertEqual(result(get_input(sample = True), steps = 1, ret_len = True), len("NCNBCHB"))
self.assertEqual(result(get_input(sample = True), steps = 2, ret_len = True), len("NBCCNBBBCBHCB"))
self.assertEqual(result(get_input(sample = True), steps = 3, ret_len = True), len("NBBBCNCCNBBNBNBBCHBHHBCHB"))
self.assertEqual(result(get_input(sample = True), steps = 4, ret_len = True), len("NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB"))
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 1588)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2, steps = 40), 2188189693529)

100
2021/15/input Normal file
View File

@ -0,0 +1,100 @@
9319927879926693924289292981328319987931316578169277696988783869228544279445229463567277999867998995
6782137819885688871167116696955987679771519589461881979722694422956389229653389717969915178729293921
4196967349617789911994968389594625922499998784199978769463894298119929998523419691416468995851998897
9939549347377981757829782892395742812959699849785339689589677539252217513971891798498155499956285578
8916384499968378766894352151499199372662869587792187795389453511569982396133971939872465668916878211
7993189556577598975327195382852888888747792768463951799884962661649859719796639872196115821997898244
9131929289774264856998314699854392321299669718664871399915973382646977184981914313583631322769869496
1294639965894198182949974183682936196887518297837684919982691938595779447911996988397175118988698494
4782786949417398178157656111741924726913693999847397789298648194156399186949891721929928386518973189
3977739884126799578896222995845591999757881477816959899697596196263475499959768799776948991584478795
8889637962317919682519681791117593699886146499419897361184928352899298889849151996897316148994198392
5498578218111924989898699181879979946886186695782915336129858857719697498544698119449189891762579543
9783338778987224568666117389627992429787741296997599911865194389848889958925553889979799897423777945
6931291694638181873998892726219973827969749895586381652183578821916888499612146683158297997879317147
8877777991334789218226394711996426411378849596468946891472988131199845489394842963873899198487952998
3539459956998578833759978911968552861677548942139916198879278837961654399499565972991281941498188981
2972974825176113221951922999797475194219955668779238484932662379576969959641999963536596939992938319
8999189987189581934744189464966714191889822969397189484166461782992252158687829572854497939177954812
9178313428786795664136631935649179965178693798648811682669769586398699789681919199495871399999741929
5119378487588899959148634498888174447189235477691334622982392398958554285539978999892599293177578576
9194483992663776979699993923694591699361753399149992817692189238678351118559919281227659784293411968
8298491567898149947916937816986611967598198918469919859981942948999997292151359196586691966622364798
8967617989988598499288583929989879191183693417868427758699995173816914799393159367299299491212938739
9615576413392678732537787848969513319795339442847871984399994395831159168113997819525821779895951131
9517289315991471929899873729491238115986618382898622168953411697612883479692345639948932996812479348
8868645925877716499872291994429779247194997924964482919991898596573118991853614924288837913727386759
9999987737841999942399299639889457399818186751988275896989726181786896522987749911978759955938769911
9965171374918978159589929157213992892387677844962317641171898612329184591217617189742176575229297129
9767929185659816969889468699589589797348131494599948496991519365572468799397762291871989292635299117
8819848216367515398912936929983168368989131886688955177399395931776416252412983329172927847866995999
6299771172636199774384692992389988965934984977999979941449596464194783797413497969982717932271631937
9867919388999249988179181792282919692511593818939811199697519413819695481976294984943596869931783348
5217498999894999148325963118872789879319591769287491854919259276994581865449967987987831114686948989
1276711298478928267591998981197998766572918373116177929646918799773629369715999986696257274486917991
9677549397288943147522629679772837189955155394128389753657889165799871691584372149499497899552724698
3161879596475993681859998589986219969799998994825365956811818594879884919881929971976965899599474911
5978899751278729229937326671598189282789189956298939976972992419825567591984699791288651863712449289
5785843757274446168989662865888761284786699589863846917179969997389799678757213693881899399798283381
9378752974919831848182681851896386931157578417822957982158836367995975749867969189559339898318939296
4993955952819489991949423696319923289965838263329551295268729531941959698478122857749736791389739479
9979913149995894544486789219787199998891969561998591837158798358549919571928399321959581987183951698
4923374226279899729129788946919681194779851147917197889998718126991737982769352816642519928221816197
9429415178891728919769972827548994887898916124219867258118175562995498488988811913466666225834984817
1997187992489979189979738887118749979626651839497889793969749472548747897714399891669799699455896479
9624951339616573939279944717971788599447979873899985998736591429797938969286363498288449419568929497
4681938983828953998696612418773812199371222792989931316197447299912596989997939419196126265222491439
8282969925999179875889569231987788869719997982677696288989132989789147471889661396777872998193215828
9117176216511922775467499987675919339161918275351989597766786989398687478371889678848583957918391983
4497298388369915739296852828574512774696251343567794471621183177947698845776887888485895669987332919
8997686994952766178877812668977742157188969917219861817661572949919915899219234859989915189987975197
4118913999874589615989952873718475897828658681851486595176248687417644198975924996249597864279743829
4579679958921889385239821828857289993449937186914896984992996922484999289511952583999869183918452997
8917999927997994429392299437994891687289495897798495953442112848382963474984728969983994991783149799
3199648699943299557924998832866891178693798554719699899858296272745997987479892662757759122991519658
3914491579265932577578942964548459979268999694999526126213913278751869812666985179899997189599921181
1269972955191548488671189591192374899912929828132891677889925885888738571982935925999913169515229987
8615958688829298177988481927419139187787699635996766899698917751758119585876873124761389897198819885
2167497889941835338936978346275288693895992191919697774591999928333652585539982922569942243597599213
9472668281589151358931112811958629285577878128176692715915826998919398155789165594481997993263959196
9966289385979919968957998245754327958389629627493188196716997492179981999971934979959984817392438989
9145599971993842923971121326227736817867637718119198819933963982629959218237898899655888386991289596
7393759917659977589146245871559799585218399497997751917777999862217868959999822795991196969818211621
9792927889945519672991946543936698168957938218225912882981935387993831231216179615298972181984319228
7743761899817767783667672977139983269215199199699918314639989519981393115896593389898441874874699776
1824497653995798679698799297229749897834797833294197979814281923987255598585839497197117839729571369
8577958882861526317942215717331978988685919519168957591892925161883496938686898898453673315687998843
4191972768117591321987488967786668869999853979339817579176251791521892919919468212444128984415671319
5576891999599798816879657775669991198999224343989577163882862748989953362179892918179279281387216996
9373769111497348825797289843198858611491499267469678187893869937361891692919973885768188384887596189
9859171731132988682195848386695958714996489139645578586441948885317994929358881751899912625863299552
4934928593958897783799983963793921184111597692919959479588985597988338527769967199293539699294774194
1698538489641947137846923886699274821953365783198463959357989161489817229999617499141136156969131969
3296989219983977948718421976373911944179536478972924859298568896972641886161529175995818483911543128
6278913998199519318855192181581196429992429817619397917141979691623919571874589999254329218897887994
9992985668416932999926168816176973997758599186957888288395128484987529129929975441231472862839421695
1362464815499699192596287679432743239657996999693751969711918999687129296564511897258489745988288167
5977189297674799199628985972999971494272992187915199889419992439287859927924778577194577929695457627
3438223999111997512849575289859985859972752399978987619891559997998554511569914599149678154711126639
2979126974919321983991789499388668896928879799646162171851776714127962589986998574331968997456544868
6216795749356515966718898985918565959499628961815279546198979459849845989371831992292699311375776865
8352715528197149369799519852288989699978992875598296779931298654369979999696915593247113843923599538
8962455899599497871221926339396845158947259529895993695544959768976848859779899991114641786957296531
2943869391171944962257474296498957919597467978896784699673793995229658928919598979738119899319383986
9983898169912296799289397793294213546919953477555577429149749497766981349668499994878593194997879275
8889882959291771612692377879435986414239649936776842748579798617821961983999949994989282378389947399
3199997769523581787587969916892769968184616564892139471917169316971672979973375871988172842996584895
8354689792844394798623128972146939743314292658383663832514698996697367378299886829789191826999773961
9893836276828919186673649859239999393698982985775768195847989769239991637411793618869888191917472289
5928583917498121999886377795189961317788981897688629942879519515624767918988389411193999247789868141
1429679799293989912693479848974118958998299151271395998911989696518192397472871957999765285698267313
9239695319699999988488829959759316161477147119979518383759198179368174993997996698566986314498599789
2582659929929648199398128693359499693417769482859853897799284585655687921188318975834353991389972842
8596473468199158355917977999874111821781368897658914981889824514189229862189929872193481817956976884
9685977168754199641189321131863836338914891329759695897928358898995849678196968239981171745482329928
9935621827798812799762166788756959219299892726731815999185647229991757173887841999993427325891658191
1778263118969552899197794341699979459118691212755668996749377169926884394172497294118899699853739749
2787591999446691168197517967271411843279629429417196194996811596363987299412785812633871145227949115
6796987473692958899138914468653236383857234899879631271399676719319916464278159525996129786399815963
5819878197925797859196414992974686679674969364619688199911487117949926999488799995986788649369962889
1611181455799765871782419643336499989899999864957323699781212598968286442487972619699128531368991998

81
2021/15/prog.py Normal file
View File

@ -0,0 +1,81 @@
from queue import PriorityQueue
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [[int(c) for c in line.strip()] for line in f.readlines()]
def in_bounds(coords, grid):
x, y = coords
w, h = len(grid[0]), len(grid)
return x >= 0 and x < w and y >= 0 and y < h
def result(inp, part = 1):
if part == 2:
new_inp = []
for y in range(5):
for row in inp:
new_row = []
for x in range(5):
for c in row:
tba = c + x + y
if tba > 9:
tba -= 9
new_row.append(tba)
new_inp.append(new_row[:])
inp = new_inp[:]
res = 0;
start = (0, 0)
end = (len(inp[0]) - 1, len(inp) - 1)
dists = [[2**30 for _ in range(len(inp[0]))] for _ in range(len(inp))]
prevs = [[(-1, -1) for _ in range(len(inp[0]))] for _ in range(len(inp))]
q = PriorityQueue()
q.put((0, start))
cur = start
while cur != end:
dist, cur = q.get()
x, y = cur
verbose(f"looking at {cur = } ({end = })")
for d in [(x-1, y), (x, y-1), (x+1, y), (x, y+1)]:
if in_bounds(d, inp):
x_, y_ = d
new_dist = dist + inp[y_][x_]
if dists[y_][x_] > new_dist:
verbose(f"\tlooking at {d = }")
prevs[y_][x_] = cur
dists[y_][x_] = new_dist
q.put((new_dist, d))
path = set()
cur = end
verbose(f"Creating path from {end = }")
while cur != (0, 0):
verbose(f"\tlooking at {cur = }")
path.add(cur)
cur = prevs[cur[1]][cur[0]]
path.add(cur)
for y, row in enumerate(inp):
for x, c in enumerate(row):
verbose((BOLD + str(c) + END) if (x, y) in path else c, end='')
verbose()
res = dists[end[0]][end[1]]
return res
BOLD = '\033[95m'
END = '\033[0m'
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

10
2021/15/sample_p1 Normal file
View File

@ -0,0 +1,10 @@
1163751742
1381373672
2136511328
3694931569
7463417111
1319128137
1359912421
3125421639
1293138521
2311944581

10
2021/15/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 40)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 315)

1
2021/16/input Normal file
View File

@ -0,0 +1 @@
40541D900AEDC01A88002191FE2F45D1006A2FC2388D278D4653E3910020F2E2F3E24C007ECD7ABA6A200E6E8017F92C934CFA0E5290B569CE0F4BA5180213D963C00DC40010A87905A0900021B0D624C34600906725FFCF597491C6008C01B0004223342488A200F4378C9198401B87311A0C0803E600FC4887F14CC01C8AF16A2010021D1260DC7530042C012957193779F96AD9B36100907A00980021513E3943600043225C1A8EB2C3040043CC3B1802B400D3CA4B8D3292E37C30600B325A541D979606E384B524C06008E802515A638A73A226009CDA5D8026200D473851150401E8BF16E2ACDFB7DCD4F5C02897A5288D299D89CA6AA672AD5118804F592FC5BE8037000042217C64876000874728550D4C0149F29D00524ACCD2566795A0D880432BEAC79995C86483A6F3B9F6833397DEA03E401004F28CD894B9C48A34BC371CF7AA840155E002012E21260923DC4C248035299ECEB0AC4DFC0179B864865CF8802F9A005E264C25372ABAC8DEA706009F005C32B7FCF1BF91CADFF3C6FE4B3FB073005A6F93B633B12E0054A124BEE9C570004B245126F6E11E5C0199BDEDCE589275C10027E97BE7EF330F126DF3817354FFC82671BB5402510C803788DFA009CAFB14ECDFE57D8A766F0001A74F924AC99678864725F253FD134400F9B5D3004A46489A00A4BEAD8F7F1F7497C39A0020F357618C71648032BB004E4BBC4292EF1167274F1AA0078902262B0D4718229C8608A5226528F86008CFA6E802F275E2248C65F3610066274CEA9A86794E58AA5E5BDE73F34945E2008D27D2278EE30C489B3D20336D00C2F002DF480AC820287D8096F700288082C001DE1400C50035005AA2013E5400B10028C009600A74001EF2004F8400C92B172801F0F4C0139B8E19A8017D96A510A7E698800EAC9294A6E985783A400AE4A2945E9170

128
2021/16/prog.py Normal file
View File

@ -0,0 +1,128 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return int(f.readlines()[0].strip(), 16)
def full_size(packet):
return 4 * (len(hex(packet)) - 2)
def version(p, size):
return p >> (size - 3)
def type(p, size):
return (p >> (size - 6)) & 0b111
def literal(p, size):
shift = size - 3 - 3
res = 0
while shift >= 0:
shift -= 5
res <<= 4
res |= (p >> shift) & 0xF
if not ((p >> (shift + 4)) & 1):
return res
raise ValueError("couldn't parse literal value correctly")
def type_id(p, size):
return (p >> (size - 7)) & 1
def len_subpackets(p, size):
return (p >> (size - 3 - 3 - 1 - 15)) & 0x7FFF
def n_subpackets(p, size):
return (p >> (size - 3 - 3 - 1 - 11)) & 0x7FF
def parse_packet(p, part = 1, size = -1):
s = 6
size = size if size != -1 else full_size(p)
res = version(p, size)
t = type(p, size)
verbose(f"{version(p, size) = }, { type(p, size) = }")
verbose(format(p, 'b').zfill(size))
if t == 4:
verbose(f"\tis literal")
n = literal(p, size)
s += 5 * (len(hex(n)) - 2)
if part == 1:
return s, version(p, size)
else:
return s, n
tid = type_id(p, size)
s += 1
ress = []
# verbose(f"{tid = }")
if tid == 0:
s += 15
tot_sub_size = len_subpackets(p, size)
verbose("VVVTTTILLLLLLLLLLLLLLL")
verbose(f"len of sub packs {tot_sub_size}")
cur_sub_size = 0
i = 0
while cur_sub_size < tot_sub_size:
verbose(f"scanning for {i = } (reducing {size} by {size - s - tot_sub_size})")
new_pack = (p >> (size - s - tot_sub_size)) & ((1 << tot_sub_size - cur_sub_size) -1)
sub_size, sub_res = parse_packet(new_pack, size = tot_sub_size - cur_sub_size, part = part)
if part == 1:
res += sub_res
else:
ress.append(sub_res)
cur_sub_size += sub_size
i += 1
s += tot_sub_size
else:
s += 11
verbose("VVVTTTILLLLLLLLLLL")
verbose(f"about to scan {n_subpackets(p, size)} packets")
for _ in range(n_subpackets(p, size)):
new_size = size - s
mask = (1 << new_size) - 1
new_pack = p & mask
sub_size, sub_res = parse_packet(new_pack, size = new_size, part = part)
s += sub_size
if part == 1:
res += sub_res
else:
ress.append(sub_res)
if part == 2:
if t == 0:
res = sum(ress)
elif t == 1:
res = 1
for r in ress:
res *= r
elif t == 2:
res = min(ress)
elif t == 3:
res = max(ress)
elif t in [5, 6, 7]:
if len(ress) != 2:
raise ValueError("huston, we got a problem")
if t == 5:
res = int(ress[0] > ress[1])
elif t == 6:
res = int(ress[0] < ress[1])
elif t == 7:
res = int(ress[0] == ress[1])
return (s, res)
def result(inp, part = 1):
return parse_packet(inp, part = part)[1]
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

49
2021/16/test.py Normal file
View File

@ -0,0 +1,49 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_pack1(self):
pack = 0xD2FE28
s = full_size(pack)
self.assertEqual(full_size(pack), 24)
self.assertEqual(version(pack, s), 6)
self.assertEqual(type(pack, s), 4)
self.assertEqual(literal(pack, s), 2021)
def test_pack2(self):
pack = 0x38006F45291200
s = full_size(pack)
self.assertEqual(full_size(pack), 56)
self.assertEqual(version(pack, s), 1)
self.assertEqual(type(pack, s), 6)
self.assertEqual(type_id(pack, s), 0)
self.assertEqual(len_subpackets(pack, s), 27)
def test_pack3(self):
pack = 0xEE00D40C823060
s = full_size(pack)
self.assertEqual(full_size(pack), 56)
self.assertEqual(version(pack, s), 7)
self.assertEqual(type(pack, s), 3)
self.assertEqual(type_id(pack, s), 1)
self.assertEqual(n_subpackets(pack, s), 3)
def test_part1(self):
self.assertEqual(result(0x8A004A801A8002F478), 16)
self.assertEqual(result(0x620080001611562C8802118E34), 12)
self.assertEqual(result(0xC0015000016115A2E0802F182340), 23)
self.assertEqual(result(0xA0016C880162017C3686B18A3D4780), 31)
def test_part2(self):
self.assertEqual(result(0xC200B40A82, part = 2), 3)
self.assertEqual(result(0x880086C3E88112, part = 2), 7)
self.assertEqual(result(0xCE00C43D881120, part = 2), 9)
self.assertEqual(result(0xD8005AC2A8F0, part = 2), 1)
self.assertEqual(result(0xF600BC2D8F, part = 2), 0)
self.assertEqual(result(0x9C005AC2F8F0, part = 2), 0)
self.assertEqual(result(0x9C0141080250320F1802104A08, part = 2), 1)
def test_spec(self):
self.assertEqual(result(0x04005AC33890, part = 2), 54)

1
2021/17/input Normal file
View File

@ -0,0 +1 @@
target area: x=29..73, y=-248..-194

64
2021/17/prog.py Normal file
View File

@ -0,0 +1,64 @@
import math, re
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
m = re.match(r"target area: x=(-?\d+)..(-?\d+), y=(-?\d+)..(-?\d+)", f.readlines()[0])
return tuple(map(lambda x: int(x), m.groups()))
def v_x(t, v0):
return max(-t + v0, 0)
def v_y(t, v0):
return -t + v0
def result(inp, part = 1):
y = abs(min(inp[2], inp[3])) - 1
v_y_max = int(y*(y+1) / 2);
if part == 1:
return v_y_max
x_2 = math.ceil((-1 + math.sqrt(1 - 4 * (-2) * inp[1])) / 2)
x_1 = math.ceil((-1 + math.sqrt(1 - 4 * (-2) * inp[0])) / 2)
x_min = inp[0]
x_max = inp[1]
y_min = inp[2]
y_max = inp[3]
global VERBOSE
res = 0
for v0x in range(x_1, x_max+1):
for v0y in range(y_min, v_y_max+1):
verbose(f"{v0x, v0y}", end = " ")
t = 0
y = 0
x = 0
while y >= y_min:
y += v_y(t, v0y)
x += v_x(t, v0x)
# verbose(f"\t{x, y = }")
if x_min <= x and x <= x_max and y_min <= y and y <= y_max:
verbose(f"accepted", end='')
res += 1
break
t += 1
verbose("")
# x = inp[1] - inp[0]
# x += x2 - x1 + 1
# verbose(f"{x1, x2 = }")
# y = abs(inp[3]) - abs(inp[2])
# y += v_y_max
return res
if __name__ == "__main__":
VERBOSE = not False
print(result(get_input(), part = 2))

1
2021/17/sample_p1 Normal file
View File

@ -0,0 +1 @@
target area: x=20..30, y=-10..-5

10
2021/17/test.py Normal file
View File

@ -0,0 +1,10 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 45)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 112)

100
2021/18/input Normal file
View File

@ -0,0 +1,100 @@
[[[0,[6,6]],[[7,2],[6,2]]],[[[9,4],[5,8]],6]]
[[[4,9],6],[[[0,1],[8,5]],[3,[7,6]]]]
[[1,7],[[[1,3],2],[[6,8],8]]]
[4,[[6,[6,0]],[[4,9],5]]]
[[3,8],[[0,6],1]]
[[2,2],[[[2,3],[2,9]],[[9,6],[4,9]]]]
[[[3,4],[[7,7],[7,8]]],[[0,2],6]]
[[[[4,4],[3,3]],[[9,0],4]],[8,[7,[6,6]]]]
[[[9,9],8],1]
[2,[[7,[1,9]],[9,2]]]
[[[[6,0],[8,2]],[[9,0],[8,7]]],[3,[6,[8,8]]]]
[[[8,[9,2]],[1,4]],[[2,2],[[1,0],5]]]
[[[9,[0,3]],[4,[2,3]]],[[8,[0,1]],[[4,8],[5,4]]]]
[[[2,0],[1,7]],[[3,[0,7]],[[7,6],0]]]
[[[1,[5,1]],[[0,3],9]],[[3,8],[[5,3],1]]]
[[[[4,5],2],[[7,7],[4,8]]],[3,[3,[6,5]]]]
[[[[4,4],4],[[5,0],2]],[9,[[0,7],5]]]
[[2,[[8,0],9]],0]
[[[[0,5],[1,0]],[0,[5,1]]],[[[0,8],[6,0]],[6,[3,9]]]]
[[[[2,4],[5,5]],[4,7]],[[[5,6],[9,5]],1]]
[[[4,[5,1]],[[6,7],1]],[1,[[5,9],4]]]
[[0,6],[[9,3],[4,2]]]
[7,[[[2,4],[3,4]],[2,0]]]
[0,[6,7]]
[[[0,2],[[7,2],7]],[[[6,3],[2,0]],[[8,6],[7,9]]]]
[[[7,[0,5]],7],[[2,3],[3,3]]]
[[2,[0,[4,5]]],[[4,[7,9]],[[5,6],4]]]
[[[5,4],0],[5,[[7,1],[7,6]]]]
[[0,3],[[[5,2],5],[[8,5],[2,8]]]]
[[[0,[8,9]],[[3,1],2]],[[3,[7,1]],7]]
[[[[9,7],[5,5]],[[2,4],1]],[[1,3],[[4,0],[9,1]]]]
[[[0,9],4],0]
[[[[8,8],9],[[8,2],3]],[[2,[7,4]],[9,1]]]
[[[1,2],8],[[[4,4],2],[2,4]]]
[[6,[7,[2,1]]],[[2,1],3]]
[0,[[[7,8],0],[5,[8,5]]]]
[[[2,8],6],[6,[[1,1],[1,2]]]]
[[[[3,9],2],[7,[4,9]]],[[[5,3],3],[[7,3],5]]]
[[2,[4,[3,2]]],[[4,9],6]]
[[[[1,1],[0,5]],[1,[4,9]]],[[6,[5,7]],[[1,6],[7,2]]]]
[0,[0,[[8,5],8]]]
[[[1,[2,5]],8],[[3,[0,2]],4]]
[[[4,3],0],[[[6,9],[7,2]],[[1,9],8]]]
[[[[7,1],0],[7,5]],[6,2]]
[[[9,[6,5]],6],[[5,5],[[4,6],2]]]
[[[[3,0],[5,5]],2],[7,[9,[8,5]]]]
[9,[[9,7],[3,3]]]
[[[0,0],4],[7,[[5,8],[2,7]]]]
[[[[9,2],4],[[0,1],[4,1]]],[[4,[6,5]],5]]
[8,[[[5,2],8],[6,0]]]
[[[[9,6],2],9],[5,[[5,3],5]]]
[[[8,[8,0]],[7,[3,3]]],[[[8,8],[5,5]],[[1,3],3]]]
[[[2,3],4],[[[8,8],[1,4]],5]]
[[[[3,7],9],6],[[5,[4,1]],4]]
[[[3,4],[[5,3],4]],[[2,[4,2]],[[0,7],5]]]
[0,9]
[[2,[[9,1],[3,4]]],[[[5,7],[6,6]],[5,[3,6]]]]
[[[[7,2],7],[[8,7],9]],[9,[[7,0],[3,4]]]]
[[[[8,3],[0,2]],0],[5,[[9,9],1]]]
[[[1,5],[[3,9],[5,6]]],[6,[2,[2,4]]]]
[[[[1,6],7],[8,9]],[[[6,7],8],1]]
[[5,[[1,3],[1,8]]],[8,1]]
[[[[4,6],9],[[3,0],[2,4]]],3]
[[[[6,6],[9,8]],[4,7]],[[6,8],1]]
[[[9,[7,8]],[4,[0,3]]],[[8,[8,1]],8]]
[4,0]
[[[[1,8],[6,9]],[[1,5],[6,1]]],[[1,9],[0,1]]]
[[[[1,8],[1,8]],[[6,2],[8,6]]],[[[6,8],3],[[8,0],[7,3]]]]
[8,9]
[[2,8],2]
[[4,[[7,0],[1,8]]],1]
[[5,0],[[[3,4],0],3]]
[[[[7,5],2],6],[[9,2],[[5,0],[7,5]]]]
[[8,[[0,0],[3,7]]],[1,6]]
[[[[5,2],[5,1]],[8,6]],[2,[9,[5,4]]]]
[[[6,[3,3]],[[0,4],0]],[[4,4],[[3,6],6]]]
[[7,[[4,9],[9,7]]],[3,[[8,7],9]]]
[[[[3,3],9],[8,[7,2]]],[[3,9],8]]
[[[0,[9,2]],1],[6,[[9,7],8]]]
[[5,[0,1]],[8,7]]
[[[[0,7],5],8],[[[0,0],[7,1]],[2,[6,9]]]]
[[5,[[3,3],7]],[[[1,3],[5,4]],[[0,8],[2,2]]]]
[[[[7,4],5],[[9,1],[5,5]]],[[0,8],[0,[6,4]]]]
[[0,[[9,5],[4,3]]],[[[2,7],[4,7]],6]]
[[7,[[3,2],[7,9]]],[[[8,6],[1,8]],[5,[5,6]]]]
[[0,[[3,3],0]],[[[5,2],[2,4]],[6,8]]]
[[[6,[5,6]],9],[[[5,2],7],[[8,7],[2,4]]]]
[[[[7,2],[8,2]],5],[[[4,5],[0,7]],6]]
[[[[6,1],4],6],[[4,[7,8]],3]]
[[[[2,6],[5,0]],5],[[3,[5,4]],[[2,3],[8,6]]]]
[[4,[[1,3],[1,3]]],[[[5,1],2],[[7,3],[9,6]]]]
[[8,[6,[0,0]]],[[[4,4],9],[6,2]]]
[[9,7],7]
[[[3,1],[[0,3],[5,2]]],3]
[[1,5],[4,[0,[3,6]]]]
[[[[4,9],[6,5]],[8,4]],2]
[[[7,[1,5]],4],[[3,[4,6]],[7,[4,3]]]]
[[[0,[5,7]],[[8,7],[2,6]]],[[4,5],5]]
[[[2,3],[[9,5],[9,3]]],[[[2,5],9],[[9,1],8]]]
[[[[4,4],4],[[4,0],9]],[[[5,3],1],[3,[7,6]]]]

184
2021/18/prog.py Normal file
View File

@ -0,0 +1,184 @@
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
import json
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [parse(json.loads(line.strip())) for line in f.readlines()]
class Pair:
def __init__(self, left, right, parent = None) -> None:
self.left = left
self.right = right
self.parent = parent
def left_most(self) -> int:
if isinstance(self.left, int):
return self.left
return self.left.left_most()
def left_most_pair(self):
if isinstance(self.left, int):
return self
return self.left.left_most_pair()
def right_most(self) -> int:
if isinstance(self.right, int):
return self.right
return self.right.right_most()
def right_most_pair(self):
if isinstance(self.right, int):
return self
return self.right.right_most_pair()
def explode(self):
if not (isinstance(self.left, int) and isinstance(self.left, int)):
raise ValueError("Both children must be ints to explode")
cur = self
while cur.parent != None and cur.parent.left is cur:
cur = cur.parent
if cur.parent != None:
if isinstance(cur.parent.left, int):
cur.parent.left += self.left
else:
cur.parent.left.right_most_pair().right += self.left
cur = self
while cur.parent != None and cur.parent.right is cur:
cur = cur.parent
if cur.parent != None:
if isinstance(cur.parent.right, int):
cur.parent.right += self.right
else:
cur.parent.right.left_most_pair().left += self.right
if self.parent != None:
if self.parent.left == self:
self.parent.left = 0
else:
self.parent.right = 0
def split_left(self):
self.left = Pair(self.left // 2, self.left // 2 + self.left % 2, self)
def split_right(self):
self.right = Pair(self.right // 2, self.right // 2 + self.right % 2, self)
def __repr__(self) -> str:
return str(self)
def __str__(self) -> str:
return f"[{str(self.left)}, {str(self.right)}]"
def __eq__(self, __o) -> bool:
try:
return self.left == __o.left and self.right == __o.right
except Exception as e:
return False
def list(self) -> str:
return [
self.left if isinstance(self.left, int) else self.left.list(),
self.right if isinstance(self.right, int) else self.right.list()
]
def __add__(self, __o):
new = Pair(self, __o)
self.parent = new
__o.parent = new
new.reduce()
return new
def reduce(self):
reduce_again = False
while True:
lvl = 0
old_queue = []
queue = [self]
new_queue = []
while len(queue) != 0 and lvl <= 4:
lvl += 1
for n in queue:
if not isinstance(n.left, int):
new_queue.append(n.left)
if not isinstance(n.right, int):
new_queue.append(n.right)
old_queue = queue[:]
queue = new_queue[:]
new_queue = []
queue = old_queue[:]
if lvl <= 4:
break
queue[0].left_most_pair().explode()
# verbose(f"{lvl = }, {queue = }")
# if lvl > 4 and len(queue) > 0:
# verbose(f"needing to explode some stuff, {queue = }")
# reduce_again = True
# for n in queue:
# n.explode()
# else:
# break
queue = [self]
new_queue = []
while len(queue) != 0:
lvl += 1
for n in queue:
if isinstance(n.left, int):
if n.left >= 10:
verbose(f"splitting left of {n}")
reduce_again = True
n.split_left()
else:
new_queue.append(n.left)
if isinstance(n.right, int):
if n.right >= 10:
verbose(f"splitting right of {n}")
reduce_again = True
n.split_right()
else:
new_queue.append(n.right)
queue = new_queue[:]
new_queue = []
if reduce_again:
self.reduce()
def mag(self):
res = 0
res += 3 * (self.left if isinstance(self.left, int) else self.left.mag())
res += 2 * (self.right if isinstance(self.right, int) else self.right.mag())
return res
def parse(arr, parent = None):
ret = Pair(None, None, parent)
ret.left = arr[0] if isinstance(arr[0], int) else parse(arr[0], ret)
ret.right = arr[1] if isinstance(arr[1], int) else parse(arr[1], ret)
return ret
def result(inp, part = 1, partial = False):
partial_res = inp[0]
for p in inp[1:]:
verbose(f"adding {partial_res} and {p}")
partial_res += p
verbose()
if partial:
return partial_res
return partial_res.mag()
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 1))

4
2021/18/sample_p1 Normal file
View File

@ -0,0 +1,4 @@
[1,1]
[2,2]
[3,3]
[4,4]

5
2021/18/sample_p2 Normal file
View File

@ -0,0 +1,5 @@
[1,1]
[2,2]
[3,3]
[4,4]
[5,5]

6
2021/18/sample_p3 Normal file
View File

@ -0,0 +1,6 @@
[1,1]
[2,2]
[3,3]
[4,4]
[5,5]
[6,6]

10
2021/18/sample_p4 Normal file
View File

@ -0,0 +1,10 @@
[[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]]
[7,[[[3,7],[4,3]],[[6,3],[8,8]]]]
[[2,[[0,8],[3,4]]],[[[6,7],1],[7,[1,6]]]]
[[[[2,4],7],[6,[0,5]]],[[[6,8],[2,8]],[[2,1],[4,5]]]]
[7,[5,[[3,8],[1,4]]]]
[[2,[2,2]],[8,[8,1]]]
[2,9]
[1,[[[9,3],9],[[9,0],[0,7]]]]
[[[5,[7,4]],7],1]
[[[[4,2],2],6],[8,7]]

10
2021/18/sample_p5 Normal file
View File

@ -0,0 +1,10 @@
[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]]
[[[5,[2,8]],4],[5,[[9,9],0]]]
[6,[[[6,2],[5,6]],[[7,6],[4,7]]]]
[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]]
[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]]
[[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]]
[[[[5,4],[7,7]],8],[[8,3],8]]
[[9,3],[[9,9],[6,[4,9]]]]
[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]]
[[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]]

108
2021/18/test.py Normal file
View File

@ -0,0 +1,108 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_eq(self):
for l in [
[1,2],
[[1, 2], 3],
[[[[[9,8],1],2],3],4],
[[[[0,9],2],3],4],
[7,[6,[5,[4,[3,2]]]]],
[7,[6,[5,[7,0]]]],
[[6,[5,[4,[3,2]]]],1],
[[6,[5,[7,0]]],3],
[[3,[2,[1,[7,3]]]],[6,[5,[4,[3,2]]]]],
[[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]],
[[3,[2,[8,0]]],[9,[5,[7,0]]]],
[[[[[4,3],4],4],[7,[[8,4],9]]],[1,1]],
[[[[0,7],4],[7,[[8,4],9]]],[1,1]],
[[[[0,7],4],[15,[0,13]]],[1,1]],
[[[[0,7],4],[[7,8],[0,13]]],[1,1]],
[[[[0,7],4],[[7,8],[0,[6,7]]]],[1,1]],
[[[[0,7],4],[[7,8],[6,0]]],[8,1]],
]:
l1 = parse(l)
l2 = parse(l)
with self.subTest(l=l, l1=l1, l2=l2):
self.assertEqual(l1, l2)
def test_parse(self):
for l in [
[1,2],
[[1, 2], 3],
[[[[[9,8],1],2],3],4],
[[[[0,9],2],3],4],
[7,[6,[5,[4,[3,2]]]]],
[7,[6,[5,[7,0]]]],
[[6,[5,[4,[3,2]]]],1],
[[6,[5,[7,0]]],3],
[[3,[2,[1,[7,3]]]],[6,[5,[4,[3,2]]]]],
[[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]],
[[3,[2,[8,0]]],[9,[5,[7,0]]]],
[[[[[4,3],4],4],[7,[[8,4],9]]],[1,1]],
[[[[0,7],4],[7,[[8,4],9]]],[1,1]],
[[[[0,7],4],[15,[0,13]]],[1,1]],
[[[[0,7],4],[[7,8],[0,13]]],[1,1]],
[[[[0,7],4],[[7,8],[0,[6,7]]]],[1,1]],
[[[[0,7],4],[[7,8],[6,0]]],[8,1]],
]:
with self.subTest(l=l):
self.assertEqual(parse(l).list(), l)
def test_explode(self):
t1 = parse([[[[[9,8],1],2],3],4])
t1.left_most_pair().explode()
t2 = parse([[[[0,9],2],3],4])
self.assertEqual(t1, t2)
t1 = parse([7,[6,[5,[4,[3,2]]]]])
t1.right_most_pair().explode()
t2 = parse([7,[6,[5,[7,0]]]])
self.assertEqual(t1, t2)
t1 = parse([[6,[5,[4,[3,2]]]],1])
t1.left.right_most_pair().explode()
t2 = parse([[6,[5,[7,0]]],3])
self.assertEqual(t1, t2)
t1 = parse([[3,[2,[1,[7,3]]]],[6,[5,[4,[3,2]]]]])
t1.left.right_most_pair().explode()
t2 = parse([[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]])
self.assertEqual(t1, t2)
t1 = parse([[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]])
t1.right_most_pair().explode()
t2 = parse([[3,[2,[8,0]]],[9,[5,[7,0]]]])
self.assertEqual(t1, t2)
def test_add_and_reduce(self):
self.assertEqual(parse([[[[4,3],4],4],[7,[[8,4],9]]]) + parse([1, 1]), parse([[[[0,7],4],[[7,8],[6,0]]],[8,1]]))
self.assertEqual(parse([[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]]) + parse([7,[[[3,7],[4,3]],[[6,3],[8,8]]]]), parse([[[[4,0],[5,4]],[[7,7],[6,0]]],[[8,[7,7]],[[7,9],[5,0]]]]))
def test_mag(self):
self.assertEqual(parse([9, 1]).mag(), 29)
self.assertEqual(parse([1, 9]).mag(), 21)
self.assertEqual(parse([[9, 1], [1, 9]]).mag(), 129)
self.assertEqual(parse([[1,2],[[3,4],5]]).mag(), 143)
self.assertEqual(parse([[[[0,7],4],[[7,8],[6,0]]],[8,1]]).mag(), 1384)
self.assertEqual(parse([[[[1,1],[2,2]],[3,3]],[4,4]]).mag(), 445)
self.assertEqual(parse([[[[3,0],[5,3]],[4,4]],[5,5]]).mag(), 791)
self.assertEqual(parse([[[[5,0],[7,4]],[5,5]],[6,6]]).mag(), 1137)
self.assertEqual(parse([[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]).mag(), 3488)
# def test_part1_partial(self):
# self.assertEqual(result(get_input(sample = True), partial = True), parse([[[[1,1],[2,2]],[3,3]],[4,4]]))
# self.assertEqual(result(get_input(sample = True, part = 2), partial = True), parse([[[[3,0],[5,3]],[4,4]],[5,5]]))
# self.assertEqual(result(get_input(sample = True, part = 3), partial = True), parse([[[[5,0],[7,4]],[5,5]],[6,6]]))
# self.assertEqual(result(get_input(sample = True, part = 4), partial = True), parse([[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]]))
# self.assertEqual(result(get_input(sample = True, part = 5), partial = True), parse([[[[6,6],[7,6]],[[7,7],[7,0]]],[[[7,7],[7,7]],[[7,8],[9,9]]]]))
# def test_part1(self):
# self.assertEqual(result(get_input(sample = True, part = 5)), 4140)
# def test_part2(self):
# self.assertEqual(result(get_input(sample = True), part = 2), 5)

6
2021/Makefile Normal file
View File

@ -0,0 +1,6 @@
N=$(shell find ./* -maxdepth 0 -type d | grep -v git | wc -l)
DIR_NAME=$(shell printf "%02d" $(N))
.PHONY: new
new:
cp -r 00_template "$(DIR_NAME)" && curl -s -H "Cookie: session=$$AOC_SESSION" "https://adventofcode.com/2021/day/$(N)/input" > "$(DIR_NAME)"/input