Talk:LA - cNteSahruPfefrlefe

We didn't solve this problem at world finals, but Steve and John worked on it for a while and the three of us came up with some insights. First off, it's easy to calculate the number of shuffles in the input. For each possible number of shuffles (1 &le; n &le; 10), there can be at most 2n deviations in the input when compared to the canonical ordering (shuffling the sorted deck n times without making any mistakes). Exactly one value of n will match these criteria, since the canonical orderings are so different for each number of shuffles.

Once you know the number of shuffles, you have to figure out the locations of the mistakes. The best strategy is to work backward from the input, "unshuffling" the cards at each step (possibly making a single mistake in the process) until the deck returns to sorted order. I recommend using an A* search, where the search heuristic is the number of mistakes left to fix. We can estimate this value by dividing the number of deviations against the canonical ordering by two. --Jeff 14:11, 9 Sep 2005 (EDT)