Magic Trick Algorithm

playing-cardsIn this blog post we are investigating whether we can teach a computer how to perform a magic trick.


If you want a computer to perform a specific task you need to provide this computer with a clear set of instructions that the computer will repeat, one instruction at a time. We call such a set of specific instructions an algorithm.

One of the key characteristic of an algorithm is that the instructions are given in a specific order, forming a sequence of instructions. When the computer will complete your algorithm, it will complete each instructions one instruction at a time in the order they appear on the algorithm. We call this sequencing, a key concept of computer algorithms.

When designing an algorithm, we can either write our instructions as a list (Pseudocode) or we can use a more visual representation of our algorithm using a flowchart.

Magic Trick Algorithm

We have implemented a magic trick algorithm based on a small deck of cards. When you press the start button below, the computer will follow the sequence of instructions from this algorithm to perform the magic trick.

Let’s see if the computer can perform this magic trick successfully:

Click on the button below to start the magic trick!

Magic Trick Algorithm/Flowchart

The flowchart for this algorithm will help you work out how the actual card trick works!
Click on the above flowchart to open in a new window.

Did you like this challenge?

Click on a star to rate it!

Average rating 3.6 / 5. Vote count: 25

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: