I have been given a task to create a code for. The task is as follows:
You are the captain of a sailing vessel and you and your crew havebeen captured by pirates. The pirate captain has all of you standingin a circle on the deck of his ship trying to decide in which orderyou should walk the plank. Eventually he decides on the followingmethod:
(a) The pirate captain asks you to pick a number N.
(b) Thefirst person to walk the plank will be the Nth person (starting fromyou).
(c) The captain will then continue around the circle forcingevery Nth person to walk the plank.
(d) Once there is only one personleft, that person will be given freedom.
For example: The crewconsists of: Andrew, Brenda, Craig, Deidre, Edward, Felicity, Greg andHarriet. Andrew selects N=2. The crew will walk the plank in the order:Brenda, Deidre, Felicity, Harriet, Craig, Greg, Edward. Andrew will begiven freedom.
The code i have so far is:
def survivor(names, step):names = ["Andrew", "Brenda", "Craig", "Deidre", "Edward", "Felicity", "Greg", "Harriet"]Next = step - 1names.pop(Next)print names
This will remove the first nth person from the list but I'm not sure how to loop through the list to keep removing the nth person.
I need it so lets assume step = 3, then i need it to remove craig and then count from craig onwards and remove the next 3rd element which is felicity and so on until there is one person left.
How can I do this?