Skip to content

Commit a7459a3

Browse files
committed
Added alternative.
1 parent 050183d commit a7459a3

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
|[07](https://adventofcode.com/2020/day/7)|Handy Haversacks|[py](/day07/main.py), [alt](/day07/alt.py)|
1212
|[08](https://adventofcode.com/2020/day/8)|Handheld Halting|[py](/day08/main.py)|
1313
|[09](https://adventofcode.com/2020/day/9)|Encoding Error|[py](/day09/main.py)|
14-
|[10](https://adventofcode.com/2020/day/10)|Adapter Array|[py](/day10/main.py)|
14+
|[10](https://adventofcode.com/2020/day/10)|Adapter Array|[py](/day10/main.py), [alt](/day10/alt.py)|
1515
|[11](https://adventofcode.com/2020/day/11)|-|-|
1616
|[12](https://adventofcode.com/2020/day/12)|-|-|
1717
|[13](https://adventofcode.com/2020/day/13)|-|-|

day10/alt.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import numpy as np
2+
3+
with open("input.txt") as file:
4+
d = sorted(map(int, file.readlines()))
5+
6+
df = np.array([1] + list(np.diff(d)) + [3])
7+
rle = np.diff([-1] + [i for i, x in enumerate(np.diff(df)) if x != 0] + [len(df)-1])
8+
m = [2**x - sum("000" in bin(y)[2:].zfill(x) for y in range(2**x)) for x in range(max(rle) + 1)]
9+
print((df == 1).sum()*(df == 3).sum())
10+
print(np.prod([m[x-1] for i, x in enumerate(rle) if i % 2 == 0]))

day10/main.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,8 @@
55
numbers = sorted([int(x) for x in f])
66

77
k = np.diff(numbers)
8-
print((1+len(k[k == 1])) * (1+len(k[k == 3])))
8+
print((1+(k == 1).sum()) * (1+(k == 3).sum()))
99

10-
# 1 --> ignore
11-
# 2 --> 1, 0 (2)
12-
# 3 --> 1 1, 1 0, 0 1, 0 0 (4)
13-
# 4 --> 1 1 1, 1 0 0, 0 1 0, 0 0 1, 1 1 0, 1 0 1, 0 1 1 (7)
1410
cands = [e for i, e in run_length.encode(np.diff([0]+numbers)) if i == 1 and e > 1]
15-
t = {2: 2, 3: 4, 4: 7}
16-
transformed = [t[e] for e in cands]
17-
print(np.prod(transformed))
11+
combinations = {2: 2, 3: 4, 4: 7}
12+
print(np.prod([combinations[e] for e in cands]))

0 commit comments

Comments
 (0)