Please implement a python program to solve the following problem, There are n integer numbers [0,1,...,n-1] forming a circle (increasing in the clockwise direction). Starting from 0 (as the 1st number), delete the m th number from the circle in the counterclockwise direction. After a number is deleted, the next starting position is the number adjacent to the deleted one going counterclockwise. Terminate the deletion when there are k numbers remaining in the circle. Please find the last k numbers remaining in the circle. The input should be n, m, k shown as follows, $ python deleteFromCircle.py 10 4 4 $ The last four numbers remaining are [0,2,5,6]
import sys
n = int(sys.argv[1])
m = int(sys.argv[2])
k = int(sys.argv[3])
lst = [i for i in range(n)]
idx = 0
while len(lst) > k:
idx = (len(lst) + idx - m + 1) % len(lst)
del lst[idx]
idx = (len(lst) + idx) % len(lst)
print(lst)
Get Answers For Free
Most questions answered within 1 hours.