A magazine where the digital world meets the real world.
On the web
- Home
- Browse by date
- Browse by topic
- Enter the maze
- Follow our blog
- Follow us on Twitter
- Resources for teachers
- Subscribe
In print
What is cs4fn?
- About us
- Contact us
- Partners
- Privacy and cookies
- Copyright and contributions
- Links to other fun sites
- Complete our questionnaire, give us feedback
Search:
Magic Memories Just Shuffling Along
"Pick a card, any card!" How often have you heard magicians say that? The normal routine is that you pick a card, the magician shuffles the deck, and abracadabra, reveals your chosen card. But behind this magic often lies some interesting maths, and as we will see later, magicians' shuffles have actually led to the development of new ways for computers to work. Let's start with a trick to amaze your friends.
The 21-card trick
The Magic effect: Have your friend shuffle a pack of cards and then you deal out single cards left to right into 3 piles of 7 cards, all face up. Your friend has to mentally select one of the cards. They mustn't tell you which card it is, but should tell you the pile it is in. You collect up the cards, and deal them out a card at a time left to right into three piles once more. Again they tell you the pile their card is in, you collect the cards once more, saying you're struggling to "read your friend's mind". Deal the cards out across the table in the three piles again in the same way. Your friend indicates the pile their card is in. Collect the cards again and deal them into the three piles one last time. You immediately announce their card and magically it is in the very middle position of the pack.
How do you perform the trick?
Let's look at the 'mechanics' of the trick. It involves several deals, each apparently shuffling the order of the cards, but doing so in a rather cunning way. In fact it's really rather simple. All you have to do is make sure you always put the pile your friend selects carefully between the other two piles and deal the pack as above. Do that and after the fourth deal the middle card of the middle pile is the chosen card, which you can reveal as you see fit. If you are having trouble getting it to work, see our more detailed instructions with pictures
Try and work out why it works, but then check our explanation.
Magic and Computers - developing your own algorithms
Once you understand the mechanics you can play with some ideas. The order of the chosen pile must not be changed, but the two other piles could for example be shuffled before being put together. As long as the chosen pile goes undisturbed between the two other piles of seven cards the order of the other cards doesn't matter. You might want to try and come up with your own additional twists once you know how it's done. The workings of this trick are what's known as an algorithm to computer scientists. The set of steps that you go through to get the trick to work are similar to the way that a computer steps through its instructions in a software program. The point about an algorithm is that if you follow its instructions exactly, you are guaranteed to achieve what you are trying to do.