To see how this amazing feat is performed, consider the pack ABCDEFGHIJKLMNOPQRST with 20 cards. Cutting and shuffling twice, then hiding the top card in the middle of the pack gives:
Cut: ABCDEFGHI JKLMNOPQRST Shuffle: JKALBCMDNEOPFGQRHSTI Cut: JKALBCMDNE OPFGQRHSTI Shuffle: OJPFKALGBQCMRHDSNTEI Hide top card in middle: JPFKALGBOQCMRHDSNTEIIf the initial order of the pack is known, cutting and shuffling k times produces 2 to the power of k interleaved sequences. Moving the top card produces 2k+1 (k is a power) sequences, one of which contains only one card. So taking out the JKLMN sequence leaves PFAGBQOCRHDSTEI. Taking out PQRST leaves FAGBOCHDEI. Taking out FGHI leaves ABOCDE and taking out ABCDE leave O. Whe know this is the card which was moved because there are 2k+1 (k is a power) sequences, and only one contains this card.
Each line of the input is the order of cards in the pack after step 4 of the trick. The pack will contain between 4 and 52 cards and have been cut and shuffled between one and four times. Each card is represented by a single letter and the initial order of a full 52 card pack is ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. Packs with n < 52 cards contain the first n of these beginning with A. The end of the input is indicated by a line containing only a #.
For each pack of cards in the input, output a line of the form
The card was q.if the chosen card can be determined or
I've failed.if it cannot.
BDEACFG AEIBCHFGDJKL JPFKALGBOQCMRHDSNTEI OPQMDHIBJCFKEGNLRSAT ABRCSDTEUFVGQWHXIYJZKaLbMcNdOePf #
The card was A. I've failed. The card was O. I've failed. The card was Q.