SHOW:
|
|
- or go back to the newest paste.
| 1 | def josephus(elements, skip): | |
| 2 | idx = 0 | |
| 3 | result = [] | |
| 4 | - | while elements: |
| 4 | + | while len(elements) > 0: |
| 5 | idx = (idx + skip - 1) % len(elements) | |
| 6 | result.append((elements.pop(idx))) | |
| 7 | ||
| 8 | return result | |
| 9 | ||
| 10 | ||
| 11 | def trim_white_spaces(elements): | |
| 12 | result = elements | |
| 13 | no_spaces = '' | |
| 14 | for num in result: | |
| 15 | if no_spaces != '': | |
| 16 | no_spaces += ',' | |
| 17 | for char in str(num): | |
| 18 | if ord(char) in range(48, 58): | |
| 19 | no_spaces += char | |
| 20 | ||
| 21 | return '[' + no_spaces + ']' | |
| 22 | ||
| 23 | ||
| 24 | elements_list = input().split() | |
| 25 | k = int(input()) | |
| 26 | ||
| 27 | print((trim_white_spaces(josephus(elements_list, k)))) |