mass suicide game

Hi,,, The problem is the following mass suicide "game": n people, numbered 1 to n, are sitting in a circle. Starting at person 1, a handgun is passed. After m passes, the person holding the gun commits suicide, the body is removed, the circle closes ranks, and the game continues with the person who was sitting after the corpse picking up the gun. The last survivor is tried for n - 1 counts of manslaughter. Thus, if m = 0 and n = 5, players are killed in order and player 5 stands trial. If m = 1 and n = 5, the order of death is 2, 4, 1, 5.

Input:
Number of People: n
Number of Passes: m
Output:
Order in which people are removed
The survivor

someone help me..
Have an array of n booleans (initially set to true for alive). Have a counter i. The person holding the gun p = i%n. If person p is dead, increment i. If he is alive, add m to i and kill the new p. Sounds like a fun game..
GAME??!!

How is this a game? ....

No matter, follow hamsterman's advice
I'd play it :P Wait... :P
Maybe the topic "mass suicide game" wasn't the best choice. How about something a bit more vague like "simulation program” o_0

You could also use vectors of people so that as the people are killed they get removed from the vector (i.e. the circle you described.) Then have an index run from 0 to n – 1, over and over until there is only one person left in the vector.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int m;
//initialize m
vector<People> circle;
//add people to the circle
int p = 0; //index of the gun holder
int click = 0; //count up untill BOOM! (...dead)
while( circle.size() > 1 ) {
  if( click >= m ) { //BOOM!
    circle[p].kill(); //...dead (optional)
    circle.erase ( circle.begin() + p ); //remove corpse person p from the circle
    click = 0; //reset gun
  } else //click... ... ... fizzle...
    click++;
  p = (p + 1) % circle.size(); //pass the gun to the next person
}
vector[0].charge_with_murder(...); // ;) 
Topic archived. No new replies allowed.