Thread: Help the soldiers!

  1. #1
    Registered User
    Join Date
    Jul 2007

    Help the soldiers!


    Please help me on this one....just tell me some basic algorithm to solve this problem...........

    A group of soldiers is surrounded by an overwhelming army force. There is no hope for victory, but there is a single horse to escape. The soldiers agree to a pact to determine which of them is to escape on the horse and summon help. Every soldier writes his name on a piece of paper and drops it in a hat. Then they form a circle. A random number n is selected. A name is picked from the hat. Starting with the soldier whose name is picked, they count clockwise around the circle. The soldier on which the count reaches n is removed from the circle. The count begins from the soldier who sat next to the removed soldier, moving in the clockwise direction. This continues until all but one soldier have been removed. The last soldier takes the horse and escapes.
    Required output:
    Using the technique used by the soldiers, display the sequence in which the soldiers are eliminated from the circle.
    Show which soldier escapes with the horse.
    Input a list of names of soldiers.
    There is no restriction on the number of soldiers.
    Make a circular list of the names of soldiers.
    Generate a random number n, which should be greater than 0 and less than the number of soldiers.
    Randomly pick a soldier to start with.
    Minimum size for soldier name=10.
    Implement it using circular linked list of a structure “node”, which contains a field for name of soldier and a pointer to the next node.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    The Homework Policy for this site discourages us from doing the homework for people, and due to the amount of people asking, I had a signature made for me that represents my POV on it.

    We can help you if you have trouble, however. Therefore, you'd be best off to come up with a solution to your homework problem, and work on it. If you have trouble with code, we might be able to help you with it. The bottom line is that we would like to help you with stuff you've already done, not do new stuff for you.

    Many of us can say from experience that these simple exercises are extremely beneficial to learning how to program. Someone on these forums likened learning to program to learning how to paint. Unless you actually do it, you can't get good at it. You can only learn so much from watching and reading through code just like watching someone else paint.

    First make sure you understand the problem. Then work out a simple solution on paper. Then work on translating the solution to extremely detailed steps in English or equivalent natural language. Finally, translate the result of that last step into C.

    Give us an idea where you're stuck with this, and let's go from there.
    Last edited by MacGyver; 07-28-2007 at 12:54 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Most popular game taken to Kuwait by soldiers
    By abachler in forum A Brief History of
    Replies: 6
    Last Post: 06-17-2008, 10:19 AM
  2. Three Brazilian Soldiers
    By Dave_Sinkula in forum A Brief History of
    Replies: 79
    Last Post: 06-10-2007, 02:14 PM
  3. US attack in Iraq (WAR Talk)
    By zahid in forum A Brief History of
    Replies: 298
    Last Post: 05-07-2003, 12:00 AM
  4. Another reason to not like America
    By Shiro in forum A Brief History of
    Replies: 129
    Last Post: 06-13-2002, 12:11 PM
  5. stuff
    By mfc2themax in forum A Brief History of
    Replies: 0
    Last Post: 10-08-2001, 01:40 AM