Ad
  • Custom User Avatar

    Thank you very much, that's a very nice message :-) I'm really happy you enjoyed it.

    Thanks @tranquility-base for the great explanation too ;-)

  • Custom User Avatar

    Trying to go through all permutations of the cards is probably the problem. The number of permutations is HUGE -- about 18 orders of magnitude larger than the estimated number of atoms making up the earth (about 10^50, see https://www.fnal.gov/pub/science/inquiring/questions/atoms.html). The crux of the kata is figuring out how to compute the permutation without brute-force enumeration (and then going the other way, figuring out where a given permutation would be in a sorted list of all possible permutations). Try working on small problems to develop intuition -- say, if you had a deck that had just 4 cards (A, B, C, and D), the possibilities are:

    A B C D

    A B D C

    A C B D

    A C D B

    A D B C

    A D C B

    ... 3 more 6-line blocks

    Note that this 6-line "A" block has sub blocks -- a 2-line "B" subblock, a 2-line "C" subblock, and a 2-line "D" subblock.

    Where would "B A C D" come -- in which 6-line block? Apply that thinking recursively. Within the "B" block, where would "A C D" come?

    Hopefully this will help get you started. And as a hint, div (//) and mod (%) are your friends!

  • Custom User Avatar

    Hi,

    Indeed, can you post parts of your code here, or you algorithms? It'll help me to undestand your question. Don't forget to mark your message as having spoilers ;-)

    Cheers