Browse Source

2016/19

master
Roderic Day 4 years ago
parent
commit
2f240f2f46
1 changed files with 20 additions and 0 deletions
  1. +20
    -0
      y2016/p19.py

+ 20
- 0
y2016/p19.py View File

import collections
import sys


text = sys.stdin.read()
lim = int(text) + 1

elves = collections.deque(range(1, lim + 1))
while len(elves) > 1:
elves.rotate(-1)
elves.popleft()
print(elves[0])

half1 = collections.deque(range(1, lim // 2 + 1))
half2 = collections.deque(range(lim // 2 + 1, lim + 1))
while half1 and half2:
half1.pop() if len(half2) < len(half1) else half2.popleft()
half2.append(half1.popleft())
half1.append(half2.popleft())
print([*half1, *half2][0])

Loading…
Cancel
Save