-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_10b.py
More file actions
34 lines (27 loc) · 800 Bytes
/
day_10b.py
File metadata and controls
34 lines (27 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
lower_delta = 1
upper_delta = 3
def NArrangements(index, jolts, n_arr):
if jolts[index] in n_arr.keys():
return n_arr[jolts[index]]
count = 0
for i in range(lower_delta, upper_delta + 1):
if index - i >= 0 and jolts[index] - jolts[index - i] <= 3:
count += NArrangements(index - i, jolts, n_arr)
n_arr[jolts[index]] = count
return count
def main():
f = open("../input/day_10_input")
jolts = list()
for line in f:
line = line.strip().replace("\n", "").replace("\r", "")
jolts.append(int(line))
jolts.append(0)
jolts.sort()
n_arr = dict()
n_arr[0] = 1
count = NArrangements(len(jolts) - 1, jolts, n_arr)
print(count)
return count
if __name__ == "__main__":
main()