January 2008 Puzzle Solution

Join Our Community of Science Lovers!


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.


Solution: 1. We are going to view the lock wheels as a counter from 0 to 999. We reset it to 000 at the beginning. We view the leftmost wheel as the hundreds place, the second from leftmost wheel as the tens place, and the rightmost wheel as the ones place.

Take the top glyph and put it on the center of the desk. Set the counter to 1 (001 read from left to right). Then proceed according to this algorithm:

After the top glyph and until the end of the left pile,
  take the next glyph g
  if g matches the glyph on the center of the desk then
    put g on the right pile
    add one to the counter
  else
    subtract one from the counter
    if the counter value is greater than 0
        move g to the right pile
    else if the counter value is 0
        move the papyrus from the desk to the right pile
        put g on the center of the desk
        set the counter to 1
    end if
  end if

After passing through all the papyri in the left pile, there will be one papyrus on the desk and 998 on the right pile. Set the counter to 1 (001) and count the number of occurrences of the glyph (that is, the number of papyri) in the center of the desk. If the counter value is 500 or more, that glyph is a majority. If not, then no glyph is in the majority.

Why does this work? Suppose that some symbol appears at least 500 times. Then it will be on the center of the desk after emptying the left pile, because it will enjoy 500 increments (additions of one) and suffer at most 499 decrements (subtractions of one). Any other symbol appearing at most N < 500 times will suffer more than N decrements. If no symbol is in the majority, then the second pass will show a count below 500.


Further reading:
The technical report  "A Fast Majority Vote Algorithm" by J. Strother Moore (University of Texas technical report 32 from 1981) is the source of this algorithm. A whole literature of "heavy hitter" algorithms has followed. In that literature, the paper of G. Manku and R. Motwani called "Approximate frequency counts over data streams" from VLDB 2002 contains a suggestive approach to the second problem. You can find both papers through your favorite search engine.

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