Skip to content

Commit 050183d

Browse files
committed
day 10
1 parent bd9808c commit 050183d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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)|-|-|
14+
|[10](https://adventofcode.com/2020/day/10)|Adapter Array|[py](/day10/main.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/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import numpy as np
2+
from more_itertools import run_length
3+
4+
with open("input.txt") as f:
5+
numbers = sorted([int(x) for x in f])
6+
7+
k = np.diff(numbers)
8+
print((1+len(k[k == 1])) * (1+len(k[k == 3])))
9+
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)
14+
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))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy