Last active
September 17, 2021 18:47
-
-
Save salva/1899d5e97818d134145825596c2b1865 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
int n = atoi(argv[1]); | |
int half = n / 2; | |
int i, j; | |
int *a = malloc(n * sizeof(int)); | |
for (j = 0, i = half; i < n ; i++, j++) a[j] = i; | |
for ( i = 0 ; i < half; i++, j++) a[j] = i; | |
int start = 0; | |
int end = n; | |
for (i = n; i > 1; i--) { | |
// for (j = start; j < end; j++) printf(" %d", a[j % n]); printf("\n"); | |
start++; | |
if (i & 1) | |
a[end++ % n] = a[start++ % n]; | |
} | |
printf("%d\n", a[start % n] + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment