Skip to content

Instantly share code, notes, and snippets.

@azarovalex
Last active October 8, 2018 17:44
Show Gist options
  • Save azarovalex/0d8e18668c38ba5b87483d2137a530b8 to your computer and use it in GitHub Desktop.
Save azarovalex/0d8e18668c38ba5b87483d2137a530b8 to your computer and use it in GitHub Desktop.
#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