Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:37:26+00:00 2026-06-14T16:37:26+00:00

I have been given a task to create a code for. The task is

  • 0

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 have
been captured by pirates. The pirate captain has all of you standing
in a circle on the deck of his ship trying to decide in which order
you should walk the plank. Eventually he decides on the following
method:

(a) The pirate captain asks you to pick a number N.

(b) The
first person to walk the plank will be the Nth person (starting from
you).

(c) The captain will then continue around the circle forcing
every Nth person to walk the plank.

(d) Once there is only one person
left, that person will be given freedom.

For example: The crew
consists of: Andrew, Brenda, Craig, Deidre, Edward, Felicity, Greg and
Harriet. Andrew selects N=2. The crew will walk the plank in the order:
Brenda, Deidre, Felicity, Harriet, Craig, Greg, Edward. Andrew will be
given freedom.

The code i have so far is:

def survivor(names, step):
    names =  ["Andrew", "Brenda", "Craig", "Deidre", "Edward", "Felicity", "Greg", "Harriet"]
    Next = step - 1
    names.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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:37:27+00:00Added an answer on June 14, 2026 at 4:37 pm

    This seems to work:

    from collections import deque
    def survivor(names, step):     
        circle = deque(names)
        while len(circle) > 1:
            circle.rotate(1-step)
            print circle.popleft()
        return circle[0]
    

    It prints the names of the pirate’s victims and returns the name of the survivor:

    In [17]: crew = ["Andrew", "Brenda", "Craig", "Deidre",
       ....: "Edward", "Felicity", "Greg", "Harriet"]
    
    In [18]: survivor(crew, 2)
    Brenda
    Deidre
    Felicity
    Harriet
    Craig
    Greg
    Edward
    Out[18]: 'Andrew'
    
    In [19]: survivor(crew, 3)
    Craig
    Felicity
    Andrew
    Edward
    Brenda
    Harriet
    Deidre
    Out[19]: 'Greg'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given a task to write a program to automatically create a
I've been given a task where I have to create a parser for a
I have been given the task to create an online (client-side) implementation of a
I have been given a task to create a bridge between C# and Java.
I have been given the task to create a shop website that allows users
I have been given the task of adding functionality to an existing IIS 6.0
I have been given the task to design a database to store a lot
I have been given the task of re-writing some libraries written in C# so
I have been given the task of devising a custom forms manager that has
I have been given the task of converting a macromedia application to a web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.