Click here to Skip to main content
15,913,205 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
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 
GeneralRe: All But One Shall Die! Pin
Richard Deeming3-Dec-13 10:16
mveRichard Deeming3-Dec-13 10:16 
Try this:
C#
int index = 1;
var prisoners = Enumerable.Range(1, 1000).ToList();
while (prisoners.Count != 1)
{
    while (index < prisoners.Count)
    {
        prisoners.RemoveAt(index);
        
        // We've killed a prisoner, so the rest of the list has moved up one place.
        // Therefore, we only need to move to the next place to skip the next prisoner.
        index++;
    }
    
    if (index == prisoners.Count + 1)
    {
        // We killed the last one in the list; start the next round with the second in the list:
        index = 1;
    }
    else
    {
        // We killed the second to last; start the next round with the first:
        index = 0;
    }
}

Console.WriteLine(prisoners[0]);




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


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

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.