@tojira/

Josephus problem

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
def lastAlive(people, killer=0):
  circle = [p for p in range(1, people + 1)]
  while len(circle) > 1:
    dead = (killer + 1) % len(circle)
    killer = (dead) % len(circle)
    del circle[dead]
  return circle[0]

people = 34
survivor = lastAlive(people)
print(survivor)