Card Tricks Special - Cs4fn

Transcription

The Magicof ComputerScience:Card Tricks SpecialorA plethora ofpasteboardparadoxespurporting theprinciples ofComputer SciencePresented byPeter McOwan and Paul Curzonof the Department of Computer Science,Queen Mary, University of Londonwith support from www.cs4fn.org

Contents4Magic and ComputerScience146The 21-card trickA perfect shuffle2418The remote control brainexperimentThe out-of-body experience4438The lightning MarrakechcalculatorThis is your chosen cardThe lottery predictionLearn more at www.cs4fn.org/mathemagic/52The square of fortune6260The future32Carry on conjuringCurtain CallQueen Mary, University of London 3

Magic andComputer Science“Pick a card, any card!” How often have youheard magicians say that? The normal routineis that you pick a card, the magician shufflesthe deck, and abracadabra, reveals your chosencard. But behind this magic often lies someinteresting maths and ideas used in computerscience, and as we shall see, magicians’ shuffleshave actually led to the development of newways for computers to work. It’s hardly surprisingthen that some of the great Magicians have alsobeen Computer Scientists or Mathematicians.Burn the witches!If, 500 years ago, you had claimed to be able tocommunicate instantaneously with someone ona different continent you would have probablybeen burnt at the stake as a witch. Nowadayswe all can do it anytime, anywhere – using ourmobile phones. Magic has become reality.Of course the technology does not need theimagined psychic powers of the Mystics.Magicians, Penn and Teller demonstratedthe principle in what may have been the mostexpensive trick of its time when done in 1990s.The televised trick took place live on the streetsof London, in Piccadilly Circus. They asked apasser-by to choose a card from a normal packof playing cards. The person took care not toshow the card to the Magicians or the camerawhich were in any case behind Penn. TheMagician shuffled then fanned the cards. Hecould immediately say which card was chosen.Psychic powers? No. High technology? Yes.Science Fiction writer Arthur CClarke summed it up with his nowfamous quote:“Any sufficientlyadvanced technology isindistinguishable from magic.”How did they do it? The camera couldn’t see thechosen card. It could see the rest of them though.Vision software analysed the picture of the fannedout cards. It quickly identified all the cards thatwere present using state-of-the art imagerecognition software and so determined the onethat was missing. The computer then connectedto the neon billboards in Piccadilly Circus andswapped the advert for a giant message namingthe missing card. As this was behind the backof the volunteer, they had no idea. It seemedamazing. Not magic though, technology. It nowreally is everyday technology, used on the streetsof London, recognising car number plates in thecongestion charging zone!How to use this bookMagicThis booklet contains a series of card tricks.Each is presented in two parts. First we presentthe magic in enough detail that with practice youshould be able to do the trick yourself. This firstpart comes in three sections. First we describethe effect that you are aiming to create. We thendescribe the detailed mechanics of the trick –actually what you do that ensures the trickworks. Finally, each trick comes with ashowmanship section. It suggests alternativeways to present the trick that may give thatall-important extra ‘wow’ factor. You can alsoexperiment with your own variations once youknow the core secret that makes the trick work.Computer ScienceAll the tricks have a link to Computer Science,though not in the obvious Penn and Teller wayof using clever technology to pull off the trick.The computer science link is to somethingdeeper than today’s technology, somethingfundamental in the subject. The second sectionof each trick describes this Computer Sciencelink. We hope you will find the science andmaths as fascinating as the tricks.Keep the Magician’s CodeSome of these effects are actually in the showsof professional magicians. We present themhere for educational and entertainmentpurposes. If you do perform them later forfriends then don’t break the magicians code.Never reveal the secrets in your tricks to youraudience.4 Queen Mary, University of LondonLearn more at www.cs4fn.org/mathemagic/Learn more at www.cs4fn.org/mathemagic/Keep thesecrets!It’s in the presentationKeep the secrets, yes, but also remember thatin magic, presentation is just as important asthe secret. Ultimately it is the final effect onyour audience that matters. With a slightlybetter presentation a trick that last week hada mediocre reception can suddenly causegasps from your audience.As we will see, computer programming is verysimilar to magic in this way. Programs combinethe code to do the job (like the secret) with auser interface (like the magician’s presentation)through which the human user interacts withthe program. Just as with a trick, the sameprogram can be transformed from unusablejunk to a best seller by getting the interfaceright. iPods are one obvious example of theeffect a revolutionary interface can have onsales. Revolutionary magic can just as easilybe down to the presentation too.Queen Mary, University of London 5

The 21-card trick: –the one where you read mindsThe magicical effectA volunteer shuffles a pack of cards. You deal outsingle cards, left to right into three piles of sevencards, all face up and visible. Your volunteermentally selects one of the cards. You read theirmind and tell them the card they are thinking of.Mind reading of course is not that easy (unlessyour volunteer is a very clear thinker with a thinskull), so you may need a bit of help.The 21-cardtrick –They mustn’t tell you which card it is, but getthem to tell you the pile it is in. You collect up thecards, and deal them out a card at a time left toright into three piles once more. Again they tellyou the pile their card is in, you collect the cardsonce more, saying you’re struggling to “read theirmind”. Deal the cards out across the table in thethree piles again in the same way. Your friendindicates the pile their card is in. Collect thecards again and deal them into the three pilesone last time. You immediately announce theircard and magically it is in the very middleposition of the pack.The mechanicsLet’s look at the ‘mechanics’ of the trick: how doyou make it work? It involves several deals, eachapparently shuffling the order of the cards, butdoing so in a rather cunning way. In fact it’sreally rather simple.All you have to do is make sure you alwaysput the pile your volunteer selects carefullybetween the other two piles and deal the packas above. Do that and after the fourth deal themiddle card of the middle pile is the chosencard, which you can reveal as you see fit.If you are having trouble getting it to work, seeour more detailed instructions with pictures atwww.cs4fn.org/mathemagic/magicshuffles/There is even a computer program there thatcan do the trick itself (and so read your mindover the Internet)!the one whereyou read mindsLaying out the 21-card trickLearn more at www.cs4fn.org/mathemagic/Queen Mary, University of London 7

The 21-card trick: –the one where you read mindsThe showmanshipShowmanship is important for a good trick.You need some patter to make things morefun and also distract attention from whatis really happening. You can come up withyour own ideas but here is a version we do.After first dealing out the cards, stare into theperson’s eyes as you try and read their mind.Tell them they shouldn’t giggle as gigglesbubbling up get in the way of the thoughts.(They probably will then struggle not to giggle).Say you need to try again as there were too manygiggles. On the second deal try it from the backof the head. After all (you explain) the front ofthe skull is the thickest part as it is important toprotect your brain. Remind them not to giggle complain it’s not working as all they are thinkingabout is not giggling instead of the card! You willneed to deal again. Try this time through theirears – stare hard and you will probably get thecolour at least. One more deal and you will haveit. Double check through the other ear to makesure it looks the same and you have it! Graduallyturn over the ones they weren’t thinking of, a fewat a time (maybe make a mistake turning overthe middle column then correct yourself).Finally their card is the one left face up.Magic and computers –developing your ownalgorithmsOnce you understand the mechanics of atrick and why it works you can play with someideas. The order of the chosen pile must notbe changed, but the two other piles could forexample be shuffled before being put together.As long as the chosen pile goes undisturbedbetween the two other piles of seven cards theorder of the other cards doesn’t matter. Youmight want to try and come up with your ownadditional twists and ways to build them intoyour presentation now you know how it’s done.Films We LovedThe Prestige isa great Oscar -nominated filmabout the rivalryof ProfessionalMagicians,Science andperhaps(?)supernaturalpowers.8 Queen Mary, University of LondonA Bit about MagiciansPersi Diaconis was aprofessional magician,but his passion to debunkcrooked casino gamespulled him into advancedmathematics. He is nowa Stanford professor ofMathematics and Statisticsstudying the randomness inevents such as coin flippingand shuffling playing cards.He and fellow mathematicianDavid Bayer have shown thatyou need to give a pack ofcards seven dovetail shufflesbefore the cards are really ina random order.Learn more at www.cs4fn.org/mathemagic/Learn more at www.cs4fn.org/mathemagic/Queen Mary, University of London 9

The 21 card-trick:The Computer ScienceStep by stepTesting timesYou want to be sure a magic trick always works.After all, it may work 99 per cent of the time butcould you be sure that the one time you’re tryingto impress a friend or in front of a big audienceit would not be the one per cent it didn’t work?I know what my luck is like!How could we make sure our algorithm is correctand our trick does work? Well we could do thetrick lots of times and check it works every time.Computer Scientists call that ‘testing’. It’s themain way programmers make sure theirprograms are correct. They run the programlots of times with different data. Would that beenough to be sure, though?Some tricks need your skill at sleight of handto work. The ones we prefer always work.Computer Scientist’s call them ‘algorithmic’.An algorithm is just a clear set of actions to betaken in a given order that achieve some task.Guaranteed!TheComputerScienceThe steps that you go through to get the 21-cardtrick to work are like this. They are also similarto the way that a computer steps through itsinstructions in a software program. All thatcomputers do, in fact, is follow instructions.They follow algorithms that programmers workout for them. The idea is that if they follow thealgorithm then they will always complete theirtask, whether it is playing chess, sending youremails or flying a plane. Every program youhave ever used is working the same way asan oversized magic trick.The point about an algorithm is that if you followits instructions exactly, you are guaranteedto achieve what you are trying to do if thealgorithm is correct. What if it isn’t? Are wereally sure our trick always works, whatever?Learn more at www.cs4fn.org/mathemagic/How many times would we need to do the magictrick to be safe? To be really certain it looks likewe would have to try it out with every possibleset of 21 cards, in all possible starting positions,checking for every card the person might havethought of.Try it. How many orders did you do before yougot bored? It’s a lot of combinations. there arefar too many to test them all. It would take animpossibly long time. Similarly testing programsexhaustively like this is not practical. Mostprograms are far more complicated thanthis simple trick after all. Instead, as manycombinations as possible are tested given thetime available. If it works each time then theprogrammer assumes it works in the casesthey didn’t try too (and hope!)That is why there are so often bugsin programs – too much hope, notenough testing!Queen Mary, University of London 11

The 21 card-trick:The Computer ScienceThere must be a better way!After Deal Number 2After Deal Number 3You deal the cards into three new piles. Wheredo those seven cards from the middle pile go?Anywhere? No. The seven possible places are:the fourth or fifth card of the first pile; the third,fourth or fifth card of the middle pile, or the thirdor fourth card of the last pile. They are just themiddle cards of each pile (as above). Thevolunteer tells you which pile again, and youagain put that pile between the other two. Thechosen card must be in the third, fourth or fifthposition of the middle pile now. Only 3 possibleplaces are left.You deal again. This time, the card has to bethe fourth card – the middle card – of the first,middle or last pile. Why? There were only threepossible places and they each get moved to themiddle of their pile as they are dealt out again.In fact more than 40 per cent of the time, it willbe in the middle pile (can you see why?), sothat’s a good pile for you to guess if you want.Once your friend tells you which of the threepiles has their card, you know exactly wheretheir card is.After Deal Number 4Perhaps we can be a bit cleverer than thatthough and work out a shorter set of tests thatstill give us the guarantee that our trick alwaysworks. With a bit of thought it’s obvious it doesn’tactually matter what any of the cards are. All thatmatters are the 21 start positions. If a card in thefirst position ends up in the centre when we testit, we can reason that every time, if a personthought of the card in that position at the start,it will end up in the middle. With this little bit ofreasoning we have reduced our testing problemto only 21 tests: one for each st

How to use this book Magic This booklet contains a series of card tricks. Each is presented in two parts. First we present the magic in enough detail that with practice you should be able to do the trick yourself. This first part comes in three sections. First we describe the effect that you are aiming to create. We then describe the detailed mechanics of the trick – actually what you do .