Close Enough

Join Our Community of Science Lovers!

The Muscle Moving Company has a bunch of heavy sculptures it wants to put in ascending order, from west to east, based on weight. However, it is not necessary to put them in precise order provided each sculpture is close to where it should be. Consider an ordering to be "k-away" if every sculpture is either in the place it should occupy according to its weight or at most in k places away from that position.

For example consider the figure

The sculpture whose weight is 9 tons is in the 9th position and the sculpture weighing 7 tons is in the 8th position so only one away from where it should be. Every other sculpture is at least two away from where it should be if the sculptures were perfectly sorted. To rectify this, Muscle swaps sculptures. For example, suppose Muscle could swap the sculpture at position 1 with the sculpture at position 4, denoting the swap as (1,4). Then Muscle could swap the sculpture at position 2 with the sculpture at position 6 (i.e. (2,6)).
This yields

Finally, (3,5) and (5,7) yields a 1-away design:


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.


In this example, Muscle got a free ride, in that two sculptures started out being at or near enough to their right places.
1. Here is a slightly harder one:

Could you help Muscle with this rearrangement? There is a method to achieve a 1-away design using only five swaps. But there may be better methods. Please give it a try.

2. Here is another initial configuration:
3 5 6 7 8 1 9 2 4
How many moves does this require to achieve the 1-away design? (Hint: I think this one is harder.)

3. Muscle wants to know the maximum number of swaps that might be necessary for nine sculptures to achieve an ascending 1-away ordering from west to east. Can you find an arrangement of 9 distinct numbers such that the number of swaps required to achieve a 1-away ordering is maximized? (Hint: Note that we are asking a "maximin" question: which initial configuration requires the maximum number of swaps assuming that you can find the best (minimal) strategy for that configuration?)

4. Clearly, if you have n numbers and you allow a (n-1)-away ordering, no swaps are needed. Can you find the worst case for d-away for every n and state how many swaps are necessary? (Hint: The result is surprising and quite beautiful.)

5. How many one-away configurations are there for n elements? (Hint: see last hint.)

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