-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday19.py
44 lines (33 loc) · 918 Bytes
/
day19.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from collections import deque
def who_gets_the_gifts(elf_count: int) -> int:
pos = 1
for i in range(1, elf_count + 1):
if pos > i:
pos = 1
# print(i, pos)
pos += 2
return pos - 2
def who_gets_the_gifts_p2(elf_count: int) -> int:
left = deque()
right = deque()
for i in range(1, elf_count + 1):
if i < (elf_count // 2) + 1:
left.append(i)
else:
right.appendleft(i)
while left and right:
if len(left) > len(right):
left.pop()
else:
right.pop()
# rotate
right.appendleft(left.popleft())
left.append(right.pop())
return left[0] or right[0]
def puzzles():
pos = who_gets_the_gifts(3014387)
print("3014387 elfs:", pos)
pos = who_gets_the_gifts_p2(3014387)
print("3014387 elfs:", pos)
if __name__ == "__main__":
puzzles()