Skip to content

Commit e56034a

Browse files
author
Vladimir Makarov
committed
AOC 2017 - day17
1 parent 22c9db0 commit e56034a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

py/advent-of-code-2017/day17.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from typing import List
2+
3+
4+
def perform_inserts(steps: int, inserts: int) -> List[int]:
5+
circle = [0]
6+
pos = 0
7+
for i in range(1, inserts + 1):
8+
pos = (pos + steps) % len(circle) + 1
9+
circle.insert(pos, i)
10+
return circle
11+
12+
13+
def part1(steps: int) -> int:
14+
target = 2017
15+
circle = perform_inserts(steps, target)
16+
index = circle.index(target) + 1
17+
return circle[index % len(circle)]
18+
19+
20+
def part2(steps: int) -> int:
21+
target = 50000000
22+
after_zero = None
23+
pos = 0
24+
size = 1
25+
for i in range(1, target + 1):
26+
pos = (pos + steps) % size + 1
27+
if pos == 1:
28+
after_zero = i
29+
size += 1
30+
return after_zero
31+
32+
33+
steps = 324
34+
print('Part 1:', part1(steps))
35+
print('Part 2:', part2(steps))

0 commit comments

Comments
 (0)