# Punchcard Searching

## by Paul Curzon, Queen Mary University of London

How were early computers able to find data stored on punch cards? They actually used the same algorithm as in a magic trick called the ‘Australian Magician’s Dream’. See in a visual way how this search algorithm works and see a practical use of binary numbers.

First Download a set of punchcards. Print them out (ideally on to thin card). Cut out each of the slots and holes, as well as the bottom corner along the dotted lines of each. The slots along the top should be cut right to the edges. It helps make sure cards don't get stuck if you sprinkle a little talcolm poweder on each sheet. Make sure all cards have the cut off corner in the same place. Shuffle the cards. Now you are ready to search for cards.

To find any numbered card, you first need to work out its binary number (so for example number 22 is 10110 in binary - the pattern spelled out in holes and slots on that card. Place a pencil through all the hole/slots labelled 1. Those with holes will shake out. As there is a 0 in that position in the binary of the number 5, DISCARD the cards that fall and keep the rest. Do the same putting the pencil in the next hole/slots of the remaining cards. This time there is a 1 in that position so KEEP those cards that fall this time. Move on to hole 4, and KEEP those that fall (a 1 in the binary), then 8 and DISCARD those that fall (a 0 in the binary), and finally 16 and KEEP those that fall (a 1 in the binary). You will be left holding card 22. You have found the card you were looking for.

You can find any numbered card this way. At each stage just follow the binary of the number you are looking for (0 means DISCARD those that fall, 1 means KEEP those that fall).

This activity features in our forthcoming book 'The Power of Computational Thinking' published by World Scientific, where you will find a fuller explanation of what is going on and its link to the magic trick.