Question: For this problem, you will be implementing a method called cursed_carousel that simulates a cursed carousel using a queue implementation. This function should take in
For this problem, you will be implementing a method called cursed_carousel that simulates a cursed carousel using a queue implementation. This function should take in 2 positive integers, n and m.
n will indicate the number of passengers on the carousel, while m indicates the kicking off factor. After the carousel starts, it acts as a queue, where the n people are numbered 1 through n and were inserted in order
[1, 2, 3, ... , n]. It then goes through the queue, only kicking off a passenger every mth time, while adding the removed people to the end of the queue.
Thus, after 1 iteration of that, the queue will look like [4 ,5, 6, ... ,n, 1, 2], while 3 has been removed and 1 and 2 were added to the end. We want you to have a function that simulates this curse and prints out the ejected rider's number until everyone has been kicked off of the carousel.
Example:
cursed_carousel(6,3)
Start with [1, 2, 3, 4, 5, 6]
Move 1 and 2 to the end, print 3.
Now we have [4, 5, 6, 1, 2]
Move 4 and 5 to the end, print 6.
Now we have [1, 2, 4, 5]
Move 1 and 2 to the end, print 4.
Now we have [5, 1, 2]
Move 5 and 1 to the end, print 2.
Now we have [5, 1]
Move 5 and 1 to the end, now 5 is at the front again, so print 5.
Now we have [1]
Move 1 to the end twice, print 1. This is in python
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
