Click here to Skip to main content
15,893,622 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
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 
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 
Found the error in my ways Smile | :)

It now works.

C#
static int FindLastManStanding(int startingPosition = 2)
 {
     int retVal = -1;
     bool lastWasKilled = false;
     List<int> dead = new List<int>();

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

     int max = captures.Max();

     for (int i = 1; i <= captures.Count; i++)
     {
         if (i % 2 == 0)
         {
             if ( max == captures[i - 1])
                 lastWasKilled = true;

             dead.Add(captures[i - 1]);
         }
     }

     dead.ForEach(x => captures.Remove(x));

     startingPosition = lastWasKilled ? 2 : 1;

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

     return retVal;
 }

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 
GeneralRe: Another one Pin
fixthebugg3-Dec-13 7:16
fixthebugg3-Dec-13 7:16 
GeneralRe: Another one Pin
OriginalGriff3-Dec-13 8:04
mveOriginalGriff3-Dec-13 8:04 

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.