This commit is contained in:
Stefan Harmuth 2020-12-10 07:47:12 +01:00
parent e666a78ba1
commit 490978ff9b
3 changed files with 184 additions and 0 deletions

53
day10.py Normal file
View File

@ -0,0 +1,53 @@
import aoclib
from functools import lru_cache
DAY = 10
TEST_SOLUTION_PART1 = 220
TEST_SOLUTION_PART2 = 19208
def part1(test_mode=False):
my_input = aoclib.getInputAsArray(day=DAY, return_type=int, test=test_mode)
adapters = set(my_input)
cur_jolt = 0
count_1 = 0
count_3 = 0
for adapter in adapters:
if adapter - cur_jolt == 1:
count_1 += 1
elif adapter - cur_jolt == 3:
count_3 += 1
cur_jolt = adapter
return count_1 * (count_3 + 1)
@lru_cache(None)
def getArrangeCount(adapter_list, cur_jolt):
count = 0
found = 0
if cur_jolt + 1 in adapter_list:
count += getArrangeCount(adapter_list, cur_jolt + 1)
found += 1
if cur_jolt + 2 in adapter_list:
count += getArrangeCount(adapter_list, cur_jolt + 2)
found += 1
if cur_jolt + 3 in adapter_list:
count += getArrangeCount(adapter_list, cur_jolt + 3)
found += 1
if found == 0:
found = 1
return count + (found - 1)
def part2(test_mode=False):
my_input = aoclib.getInputAsArray(day=DAY, return_type=int, test=test_mode)
adapters = frozenset(my_input)
return getArrangeCount(adapters, 0) + 1

100
inputs/10 Normal file
View File

@ -0,0 +1,100 @@
46
63
21
115
125
35
89
17
116
90
51
66
111
142
148
60
2
50
82
20
47
24
80
101
103
16
34
72
145
141
124
14
123
27
62
61
95
138
29
7
149
147
104
152
22
81
11
96
97
30
41
98
59
45
88
37
10
114
110
4
56
122
139
117
108
91
36
146
131
109
31
75
70
140
38
121
3
28
118
54
107
84
15
76
71
102
130
132
87
55
129
83
23
42
69
1
77
135
128
94

31
inputs/10_test Normal file
View File

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