FYI.

This story is over 5 years old.

Tech

How an Algorithm Learned to Do Magic Tricks

Researchers designed an algorithm that can design better magic tricks than human magicians, and you can use it at home.
A scan of the puzzle. Image: Howard Williams

​Magic tricks require a bit of mystery to impress and fascinate. A convincing speech or appropriate theatrics by a human magician can make a skeptical audience believe in the impossible. But can a computer do the same?

Researchers at the Queen Mary University in London built an algorithm capable of designing convincing tricks like a "magic" jigsaw puzzle that uses geometric principles to make it appear as though shapes on the board have disappeared when its tiles are rearranged, and an app that can guess what card you picked out of a rigged deck.

Advertisement

These types of tricks are mathematically based, the researchers explain in a new paper published today in Frontiers In Psychology. The jigsaw puzzle involves calculating the number of pieces, the size of the puzzle, the number of shapes, and more. The card trick requires one to consider card preferences and the cyclical ordering of cards in a deck.

An algorithm can make these kinds of math-based tricks even better by using computational abilities that likely outmatch your average magician.

"Traditionally, these tricks were created intuitively by magicians and trick designers," Howard Williams, co-author of the study, told me. "Just looking at them and realizing that they have a mathematical underpinning that can be modelled by a computer was the genesis of the idea."

Williams and his colleague, Peter McOwan, fed their algorithm a set of mathematical constraints for the creation of a specific trick as well as psychological data to guide the program to solutions that can work in the real world.

For the mind-reading card trick, the researchers tested subjects to find out which cards in a deck were generally preferred; the ace of hearts versus the two of clubs, for example. That data was then used by the algorithm in conjunction with constraints, like the appropriate positioning of "liked" cards throughout the deck, to generate an ideal deck of cards engineered to improve the illusion.

The researchers then built an Android app that acted like a digital magician's assistant. By deploying the custom engineered trick deck and entering responses to simple questions like, "Are you thinking of a red card?" into the software, the algorithm was able to predict what card was selected. Just like a human magician.

Advertisement

The app running on an HTC phone. Image: Howard Williams

According to Williams, computational magic was a hit with the people they tested it on."People seem to transfer the kind of magical power of the trick, if you like, from the magician to the phone," he said. "It was as though they felt the magician was getting the phone to do something that the phone shouldn't be able to do."

This finding is particularly interesting. Can technology, although we understand that it is engineered and far from supernatural, be perceived as magical? Arthur C. Clarke, sci-fi nerds may recall, once wrote that "any sufficiently advanced technology is indistinguishable from magic."

A smartphone that can guess what card you picked is likely a sight less advanced than whatever Clarke was imagining when he penned that a particular aphorism, but it draws attention to the fact that technology can still surprise us and inspire awe, even if we understand its workings on a conceptual level.

Of course a phone can guess what card you picked or monitor your social life and keep a catalogue of the faces and names of people you meet. That's the kind of thing that smartphones just do. But do you understand how? Really?

Even if a computer that can pull off a convincing card trick or design a puzzle seems like a gimmicky use of artificial intelligence, it's nonetheless a reminder that technology can still fill us with a certain sense of wonder, no matter how small.