Posts

Showing posts with the label Mousetrap

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...

Google Code Jam: Mousetrap in 4 languages - GAME OVER

First of all, I would like to thank the Google team for Code Jam opportunity, and its organization: AMAZING! Yesterday I have lost my Round without a single commit. This time I have not excuses, it was simply my fault. I did not understand properly first two problems, or better, expected results, but I was sure the reason was my poor English knowledge, and I wouldn't be silly, asking silly questions (some question was silly enough, so, next time, I'll be less shy than this time). Accordingly, since Code Jam is a challenge, I chose to solve the most difficult problem, the Mousetrap. First of all, because the problem, and the expected result, was so simple to understand, secondly, because it was the best one for points :geek: Problem Analysis Ok, we had 2 hours to analyse the problem, to find the best solution, and to commit results, and this time I did not even download the test, because I would like to be sure that my solution was good enough to solve the problem. Count positio...