Browse Source

Add day 10

master
mid-kid 4 years ago
parent
commit
3c3a10905b
  1. 27
      d10.py
  2. 101
      d10_input.txt
  3. 2
      d10_output.txt

27
d10.py

@ -0,0 +1,27 @@
#!/usr/bin/env python3
from sys import argv
i = {int(x.strip()) for x in open(argv[1])}
i.add(0)
i.add(max(i)+3)
s = sorted(list(i))
di = [0]*3
for x in range(len(s)-1):
d = s[x+1] - s[x]
di[d-1] += 1
print(di[0]*di[2])
ch = {}
def f(x):
if x not in i:
return 0
if x in ch:
return ch[x]
c = f(x+1) + f(x+2) + f(x+3)
if not c:
c += 1
ch[x] = c
return c
print(f(0))

101
d10_input.txt

@ -0,0 +1,101 @@
104
83
142
123
87
48
102
159
122
69
127
151
147
64
152
90
117
132
63
109
27
47
7
52
59
11
161
12
148
155
129
10
135
17
153
96
3
93
82
55
34
65
89
126
19
72
20
38
103
146
14
105
53
77
120
39
46
24
139
95
140
33
21
84
56
1
32
31
28
4
73
128
49
18
62
81
66
121
54
160
158
138
94
43
2
114
111
110
78
13
99
108
141
40
25
154
26
35
88
76
145

2
d10_output.txt

@ -0,0 +1,2 @@
2201
169255295254528
Loading…
Cancel
Save