Last active
October 8, 2018 17:44
-
-
Save azarovalex/0d8e18668c38ba5b87483d2137a530b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define N 5 | |
#define M 3 | |
int main() { | |
int arrayOfGuys[N] = { 0 }; | |
int firstFiveGuys[5] = { 0 }; | |
int pointerInArrayOfFirstFive = 0; | |
int counter = 0; | |
int pointer = 0; | |
int numOfDeleted = 0; | |
while (numOfDeleted != (N - 1)) { | |
if (arrayOfGuys[pointer] == 0 && ++counter == M) { | |
arrayOfGuys[pointer] = 1; | |
numOfDeleted++; | |
if (pointerInArrayOfFirstFive < 5) { | |
firstFiveGuys[pointerInArrayOfFirstFive++] = pointer; | |
} | |
counter = 0; | |
} | |
pointer = (pointer + 1) % N; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment