March 2005 Puzzle Solutions

1. Here is a solution that requires only five swaps for


9 8 7 1 4 3 5 6 2 (1,9): 2 8 7 1 4 3 5 6 9 (2,7): 2 5 7 1 4 3 8 6 9 (2,4): 2 1 7 5 4 3 8 6 9 (3,8): 2 1 6 5 4 3 8 7 9 (3,6): 2 1 3 5 4 6 8 7 9

2. For this initial configuration
3 5 6 7 8 1 9 2 4
six swaps are sufficient. Here is one method to put it into a 1-away configuration:

3 5 6 7 8 1 9 2 4 (5,9): 3 5 6 7 4 1 9 2 8 (The 4 and 8 are now close enough.) (1,3): 6 5 3 7 4 1 9 2 8 (1,6): 1 5 3 7 4 6 9 2 8 (The 4, 8, 1, 3 and 6 are now close enough) (2,4): 1 7 3 5 4 6 2 9 8 (7,8): 1 7 3 5 4 6 2 9 8 (2,7): 1 2 3 5 4 6 7 9 8 Can you do better?


On supporting science journalism

If you're enjoying this article, consider supporting our award-winning journalism by subscribing. By purchasing a subscription you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.


3. Here is a very bad initial configuration for nine items:
8 9 1 2 3 4 5 6 7.

Each element is two away from its correct position. Each swap can do no better than moving a single sculpture into its correct position. Yet once the first seven sculptures are in place, the last two will be only one away, so seven moves is the worst case.

4. Omniheurist Tom Rokicki came up with the following beautiful solution (my colleague Richard Cole and mathematician Ivan Rezanka had similar intuitions).

One maximally bad initial configuration when the goal is to achieve a d-away configuration is to start with a d+1 rotation from the in-order configuration. For example, when d = 1, the configuration
8 9 1 2 3 4 5 6 7 is a 2-rotation. By contrast a 6-rotation (useful for to maximize the number of swaps when the goal is to achieve a 5-away configuration) on 9 elements yields:
4 5 6 7 8 9 1 2 3

Rokicki observed that there will be n-(d+1) numbers that are at least d+1 out of place (1, 2, 3 in the 6-rotation example), all in the same direction. Each swap can move only a single one of those numbers into range of its location.

Swapping them into place in order (for this example, swapping the 1 at position 7 with the 4 at position 1, then the 2 at position 8 with the 5 at position 2, and so on) is in fact an optimal solution.

In fact, no matter which initial configuration one starts with, one can swap 1 into place, then 2, then 3, and so on up to the largest d+1 sculptures. Those last ones are no more than d away from their proper places.

5. How many 1-away configurations are there for n elements?

Recall the Fibbonaci sequence that seems to come up in so much of mathematics:
1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Each number is the sum of the two previous ones, i.e., fib(k+2) = fib(k+1) + fib(k). Let's identify the numbers by their position in that list, so fib(0) = fib(1) = 1, fib(6) = 13 (remember we're starting from 0), and so on.

Well, the number of 1-away arrangements (including the perfectly sorted one) of n elements is just fib(n).

For n = 1, there is clearly just one (fib(1)).
For n = 2, there are two: 1 2 and 2 1.
For n = 3, there are three: 1 2 3; 1 3 2; 2 1 3
For n = 4, there are five: three that involve 2 3 4 with 1 fixed; then swap the 1 and 2 and there are two arrangements of 3 and 4.

In general, there are fib(n-1) permutations of length n with the first sculpture in place. If the first sculpture is not in place it must be at position 2, but this means the second sculpture must be in position 1 (no other element can be in position 1). So this fixes the first two positions out of order. Now there are there are fib(n-2) permutations of the last n-2 sculptures.

This last result was first discovered in the following nicely written article (in French) that you can find on the web:
"Quelques resultats dans la metrique des permutations,"by Rene Lagrange, Annales scientifiques de l'E.N.S. third series, tome 79, no 3, 1962, pp. 199-241.
http://archive.numdam.org/article/ASENS_1962_3_79_3_199_0.pdf

It’s Time to Stand Up for Science

If you enjoyed this article, I’d like to ask for your support. Scientific American has served as an advocate for science and industry for 180 years, and right now may be the most critical moment in that two-century history.

I’ve been a Scientific American subscriber since I was 12 years old, and it helped shape the way I look at the world. SciAm always educates and delights me, and inspires a sense of awe for our vast, beautiful universe. I hope it does that for you, too.

If you subscribe to Scientific American, you help ensure that our coverage is centered on meaningful research and discovery; that we have the resources to report on the decisions that threaten labs across the U.S.; and that we support both budding and working scientists at a time when the value of science itself too often goes unrecognized.

In return, you get essential news, captivating podcasts, brilliant infographics, can't-miss newsletters, must-watch videos, challenging games, and the science world's best writing and reporting. You can even gift someone a subscription.

There has never been a more important time for us to stand up and show why science matters. I hope you’ll support us in that mission.

Thank you,

David M. Ewalt, Editor in Chief, Scientific American

Subscribe