Mousetrap in C language
Just for fun, and performances are horribles as well in new C version, performances are great until 5000 cards, so I need to remove some dust from my good old ANSI C book :D New version, compatible with gcc compiler. To create and use the executable, gcc Mousetrap.c Then call the file Mousetrap 5, for example, to obtain 1,3,2,5,4 Works quickly until 5000 results, requires a monster PC for 1000000 Google limit (algo is still not perfect, but this can generate an entire deck, instead of getting only that index, for each index) #include <stdlib.h> int *perfectDeck(int cards); int main(int argc, char **argv){ if(--argc){ *argv++; int i = 0, cards = atoi(*argv); if(cards > 0){ int *result = perfectDeck(cards); printf("%i", result[i++]); while(i printf(" %i", result[i++]); free(result); } } return 0; } int *perfectDeck(int cards){ i...