This commit is contained in:
Tim Stallard 2020-12-10 08:14:29 +00:00
parent 311803374b
commit 5c5499f33f
5 changed files with 160 additions and 0 deletions

4
10/1.py Normal file
View File

@ -0,0 +1,4 @@
nums = sorted([int(l) for l in open("input", "r").read().split("\n") if l])
nums = [0] + nums + [nums[-1]+3]
diffs = [b - a for (a, b) in zip(nums[:-1], nums[1:])]
print(len([n for n in diffs if n == 1]) * len([n for n in diffs if n == 3]))

7
10/2.py Normal file
View File

@ -0,0 +1,7 @@
nums = sorted([int(l) for l in open("input", "r").read().split("\n") if l])
nums = [0] + nums + [nums[-1]+3]
diffs = [b - a for (a, b) in zip(nums[:-1], nums[1:])]
groups = "".join([str(n) for n in diffs]).split("3")
maps = {1: 2, 2: 4, 3: 7}
from functools import reduce
print(reduce(lambda a, b: a * b, [maps[len(g) - 1] for g in groups if len(g) > 1]))

107
10/input Normal file
View File

@ -0,0 +1,107 @@
83
69
170
56
43
111
117
135
136
176
154
65
107
169
141
151
158
134
108
143
114
104
49
55
72
73
144
13
35
152
98
133
31
44
150
70
118
64
39
137
142
28
130
167
101
100
120
79
153
157
89
163
177
3
1
38
16
128
18
62
76
78
17
63
160
59
175
168
54
34
22
174
53
25
129
90
42
119
92
173
4
166
19
2
121
7
71
99
66
46
124
86
127
159
12
91
140
52
80
45
33
9
8
77
147
32
95

31
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

11
10/test2 Normal file
View File

@ -0,0 +1,11 @@
16
10
15
5
1
11
7
19
6
12
4