Wrox Home  
Puzzles for Programmers and Pros
by Dennis E. Shasha
May 2007, Paperback

Solution to Winning at the Slots

1. Can you show how to guarantee to win in 36 lever pulls?

Here are the 36 lever pulls that will guarantee that every possible value of the first wheel is combined with every pair of values from each pair of other wheels.

num wheel1 wheel2 wheel3 wheel4 wheel5
1 apples pears apples pears apples
2 apples cherries apples apples grapes
3 apples grapes apples cherries cherries
4 apples cherries grapes cherries apples
5 apples pears pears cherries grapes
6 apples cherries pears pears cherries
7 apples pears grapes apples cherries
8 apples grapes pears apples apples
9 apples grapes grapes pears grapes
10 cherries pears apples pears apples
11 cherries cherries apples apples grapes
12 cherries grapes apples cherries cherries
13 cherries cherries grapes cherries apples
14 cherries pears pears cherries grapes
15 cherries cherries pears pears cherries
16 cherries pears grapes apples cherries
17 cherries grapes pears apples apples
18 cherries grapes grapes pears grapes
19 grapes pears apples pears apples
20 grapes cherries apples apples grapes
21 grapes grapes apples cherries cherries
22 grapes cherries grapes cherries apples
23 grapes pears pears cherries grapes
24 grapes cherries pears pears cherries
25 grapes pears grapes apples cherries
26 grapes grapes pears apples apples
27 grapes grapes grapes pears grapes
28 pears pears apples pears apples
29 pears cherries apples apples grapes
30 pears grapes apples cherries cherries
31 pears cherries grapes cherries apples
32 pears pears pears cherries grapes
33 pears cherries pears pears cherries
34 pears pears grapes apples cherries
35 pears grapes pears apples apples
36 pears grapes grapes pears grapes

This article is based on Puzzles for Programmers and Pros (Wrox, 2007, ISBN: 978-0-470-12168-9) by Dr. Dennis Shasha. Dr. Shasha is a professor of Mathematical Sciences in the Department of Computer Science at NYU. Along with research and teaching in biological computing, pattern recognition, database tuning, cryptographic file systems, and the like, he is well-known for his mathematical puzzle column for Dr. Dobbs whose readers are very sharp and his Puzzling Adventures Column for the Scientific American. His puzzle writing has given birth to fictional books about a mathematical detective named Dr. Ecco. Dr. Shasha has also co-authored numerous highly technical books and speaks often at conferences