Advertisement
furas

100 people in circle, killing next one.

May 23rd, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. # 100 people stay in circle, first have sword and kill second,
  2. # and he gives sword to next one (third) which kills next one (forth), etc.
  3. # Finally last only one. Which one ?
  4.  
  5. data = list(range(1, 101))
  6.  
  7. position = 1 # first killed (not first killing) - it is list index (which starts at 0), not person number (which start at 1)
  8.  
  9. while len(data) > 1:
  10.     print('killed:', data.pop(position))
  11.     position = (position+1) % len(data)
  12.  
  13. print('last:', data[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement