Add “magician” to the list of careers that may one day be overtaken by computers. Researchers at Queen Mary University of London successfully taught artificial intelligence to fool human onlookers with magic tricks. Specifically, a puzzle illusion and a “mind reading” trick.

The researchers’ goal was to see how magic can be assisted when “human intelligence is replaced or assisted by machine intelligence,” Howard Williams and Peter W. McOwan, the project’s leaders, write in the journal Frontiers. Of course, magic tricks are as much smoke and mirrors as they are skillful sleight of hand, and since a computer program doesn’t have much of a stage presence and can’t trick you with theatrics, researchers gave it another, fool-proof magical tool to work with: math.

For its first trick, the computer fooled spectators’ eyes with a jigsaw puzzle covered in images that seem to increase and decrease in number depending on how the puzzle is arranged. The trick is based on what’s called “The Principle of Concealed Distribution.” By redistributing one small section of one shape among other shapes, you can make it seem as though the total number of shapes changes without actually removing or adding any of the pieces. Sounds confusing, but watch:

These kinds of puzzles are complex for humans to perform, but a piece of cake for a computer wielding an algorithm. “It is typical to assume a jigsaw puzzle can be put together in only one way,” the researchers write. So, when we see this puzzle change before our eyes, our brain thinks we’ve observed something that isn’t physically possible, something magical.

Indeed, when researchers asked participants to explain the trick, some “reported having no idea how the trick worked.” Others guessed or said it was an optical illusion. The puzzle was so confounding, a version of it is now being successfully sold at a magic store in London, which has already asked for more to restock its shelves.

But optical illusions are paltry parlor tricks compared to the computer’s other skill: reading minds. The program, in the form of an Android app called Phoney, can accurately predict the number and suit of a single card plucked from a normal playing deck. It does this with a little cooperation from a human helper, who loads the deck by putting the cards in a specific pattern, which remains constant even when the deck is cut.

The pattern made it possible for a specific card to be identified with only a small amount of information to go on. And the app knows we have specific cards we prefer, like face cards, hearts and spades. A spectator chooses a card and tells the magician something about it, like its color. From there, based on the deck’s pattern and human preference, the app can accurately decipher which card was chosen. Watch:

In trials, researchers were surprised audiences weren’t more freaked out by the tricks. “We suspected that audiences would be suspicious of the involvement of technology in the delivery of a trick but we’ve found out that isn’t the case.” McOwan says.

The hope is that AI can help enhance the magic experience. “Computer intelligence can process much larger amounts of information and run through all the possible outcomes in a way that is almost impossible for a person to do on their own,” Williams says. “So while a member of the audience might have seen a variation on this trick before, the AI can now use psychological and mathematical principles to create lots of different versions and keep audiences guessing.”