You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4 anni fa
1234567891011121314151617181920
  1. import collections
  2. import sys
  3. text = sys.stdin.read()
  4. lim = int(text) + 1
  5. elves = collections.deque(range(1, lim + 1))
  6. while len(elves) > 1:
  7. elves.rotate(-1)
  8. elves.popleft()
  9. print(elves[0])
  10. half1 = collections.deque(range(1, lim // 2 + 1))
  11. half2 = collections.deque(range(lim // 2 + 1, lim + 1))
  12. while half1 and half2:
  13. half1.pop() if len(half2) < len(half1) else half2.popleft()
  14. half2.append(half1.popleft())
  15. half1.append(half2.popleft())
  16. print([*half1, *half2][0])