/*QUE: 100 people standing in a circle in an order 1 to 100. No. 1 has a sword. He kills the next person (i.e. No. 2) and gives the sword to the next (i.e. No. 3). All people do the same until only 1 survives. Which number survives at the last?
There are 100 people starting from 1 to 100. */
using System;
using System.Linq;
public class Program
{
// Driver code
static public void Main ()
int person = 200;
// Placeholder array for person
int[] a = new int[person];
// Assign placeholders from 1 to N (total person)
for (int i = 0; i < person; i++) {
a[i] = i + 1;
}
// Will start the game from 1st person (Which is at
// placeholder 0)
int pos = 0;
// Game will be continued till we end up with only one
// person left
while (a.Length > 1)
// Current person will shoot the person next to
// him/her. So incrementing the position.
pos++;
// As person are standing in circular manner, for
// person at last place has right neighbour at
// placeholder 0. So we are taking modulo to make it
// circular
pos %= a.Length;
// Killing the person at placeholder 'pos'
// To do that we simply remove that element
a = a.Where((source, index) =>index != pos).ToArray();
// There is no need to increment the pos again to
// pass the gun Because by erasing the element at
// 'pos', now next person will be at 'pos'.
// Print Person that survive the game
Console.Write(a[0]);