Question

Please implement a python program to solve the following problem, There are n integer numbers [0,1,...,n-1]...

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]

Homework Answers

Answer #1

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)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n,...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n, a positive integer, it returns a list of n tuples corresponding to the numbers 1 through n (both inclusive): the tuple for the number k consists of k as the first component, and exactly one of the following strings as the second: • the string 'two!' if k is divisible by 2 • the string 'three!' if k is divisible by 3 • the...
Use Python to Complete the following on a single text file and submit your code and...
Use Python to Complete the following on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples: Sum all the items in a list. Multiply all the items in a list. Get the largest number from a list. Get the smallest number from a list. Remove duplicates from a list. Check a list is empty or not. Clone or copy...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...