Click here to Skip to main content
15,894,896 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: All But One Shall Die! Pin
Abhinav S3-Dec-13 7:48
Abhinav S3-Dec-13 7:48 
GeneralRe: All But One Shall Die! Pin
Nagy Vilmos3-Dec-13 7:58
professionalNagy Vilmos3-Dec-13 7:58 
GeneralRe: All But One Shall Die! Pin
Richard Deeming3-Dec-13 8:19
mveRichard Deeming3-Dec-13 8:19 
GeneralRe: All But One Shall Die! Pin
Nagy Vilmos3-Dec-13 8:22
professionalNagy Vilmos3-Dec-13 8:22 
GeneralRe: All But One Shall Die! Pin
Richard Deeming3-Dec-13 8:30
mveRichard Deeming3-Dec-13 8:30 
GeneralRe: All But One Shall Die! Pin
Nagy Vilmos3-Dec-13 8:36
professionalNagy Vilmos3-Dec-13 8:36 
GeneralRe: All But One Shall Die! Pin
Richard Deeming3-Dec-13 8:42
mveRichard Deeming3-Dec-13 8:42 
GeneralRe: All But One Shall Die! Pin
ednrg3-Dec-13 9:58
ednrg3-Dec-13 9:58 
This is nasty and sloppy, but it figures it out to be 505. Where did I got wrong (other than write some horrific code Laugh | :laugh: )?

C#
class Program
{
    static List<int> captures = new List<int>();

    static void Main(string[] args)
    {
        PopulateCaptures();
        int survivor = FindLastOne();

        Console.WriteLine("The last one is: {0}", survivor);

        Console.Write("\n\nHit any key to continue...");
        Console.ReadKey();
    }

    static void PopulateCaptures()
    {
        for (int i = 1; i <= 1000; i++)
            captures.Add(i);
    }

    static int FindLastOne(int startingPosition = 0)
    {
        int retVal = -1;

        List<int> dead = new List<int>();

        if (captures.Count == 1)
        {
            retVal = captures[0];
            return retVal;
        }

        if (startingPosition == 0)
            startingPosition = 2;

        if (startingPosition == 1)
            captures.RemoveAt(0);

        for (int i = 1; i <= captures.Count; i++)
        {
            if (i % 2 == 0)
            {
                dead.Add(captures[i - 1]);
            }
        }

        foreach (int i in dead)
        {
            captures.Remove(i);
        }

        if (captures.Count % 2 != 0)
            startingPosition = 1;

        if (captures.Count == 1)
            retVal = captures[0];
        else
            retVal = FindLastOne(startingPosition);

        return retVal;
    }
}

GeneralRe: All But One Shall Die! Pin
Richard Deeming3-Dec-13 10:16
mveRichard Deeming3-Dec-13 10:16 
GeneralRe: All But One Shall Die! Pin
ednrg4-Dec-13 8:05
ednrg4-Dec-13 8:05 
AnswerRe: All But One Shall Die! Pin
CDP18023-Dec-13 7:22
CDP18023-Dec-13 7:22 
GeneralRe: All But One Shall Die! Pin
OriginalGriff3-Dec-13 8:03
mveOriginalGriff3-Dec-13 8:03 
GeneralRe: All But One Shall Die! Pin
JMK894-Dec-13 4:42
professionalJMK894-Dec-13 4:42 
GeneralRe: All But One Shall Die! Pin
OriginalGriff4-Dec-13 5:11
mveOriginalGriff4-Dec-13 5:11 
GeneralRe: All But One Shall Die! Pin
Richard Deeming3-Dec-13 8:12
mveRichard Deeming3-Dec-13 8:12 
GeneralRe: All But One Shall Die! Pin
Nagy Vilmos3-Dec-13 8:20
professionalNagy Vilmos3-Dec-13 8:20 
AnswerRe: All But One Shall Die! Pin
ednrg5-Dec-13 6:12
ednrg5-Dec-13 6:12 
GeneralAnother one Pin
Abhinav S3-Dec-13 6:43
Abhinav S3-Dec-13 6:43 
GeneralRe: Another one Pin
enhzflep3-Dec-13 7:02
enhzflep3-Dec-13 7:02 
GeneralRe: Another one Pin
Abhinav S3-Dec-13 7:06
Abhinav S3-Dec-13 7:06 
GeneralRe: Another one Pin
enhzflep3-Dec-13 10:37
enhzflep3-Dec-13 10:37 
GeneralRe: Another one Pin
MehGerbil3-Dec-13 7:08
MehGerbil3-Dec-13 7:08 
GeneralRe: Another one Pin
Nagy Vilmos3-Dec-13 7:08
professionalNagy Vilmos3-Dec-13 7:08 
GeneralRe: Another one Pin
fixthebugg3-Dec-13 7:11
fixthebugg3-Dec-13 7:11 
GeneralRe: Another one Pin
Nagy Vilmos3-Dec-13 7:13
professionalNagy Vilmos3-Dec-13 7:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.