1 University of Illinois Chicago (UNITED STATES)
2 Loyola University Chicago (UNITED STATES)
About this paper:
Appears in: EDULEARN22 Proceedings
Publication year: 2022
Pages: 3240-3248
ISBN: 978-84-09-42484-9
ISSN: 2340-1117
doi: 10.21125/edulearn.2022.0794
Conference name: 14th International Conference on Education and New Learning Technologies
Dates: 4-6 July, 2022
Location: Palma, Spain
Magic can be used in project-based instruction to motivate students and provide a meaningful context for students learning computer programming. This work describes two “magic” programs, of the “Guess a Number” or “Mind-reader” variety, making connections to the underlying computing concepts.

The science fiction writer Arthur C. Clarke wrote that “any sufficiently advanced technology is indistinguishable from magic.” As technology continues to grow at an exponential rate, new applications regularly arise that surprise us in what they can do. We capitalize on this trend by creating assignments and demonstrations that are magical, captivating students’ attention so that they want to understand and replicate these themselves, showing them to their friends and family. This investment of attention motivates students to invest in learning the underlying programming concepts.

The first example presents a table of numbers, where each one is associated with a seemingly random letter. Participants choose an initial number and then do some simple math to find a second number. The program then tells them which letter is next to their number. In the second example, a student volunteer chooses a secret number, such as the age at which they hope to market a wildly successful app. The volunteer is then presented with six boxes with numbers in them, and asked to indicate which boxes have their number. The presenter then guesses their number. Each of these examples illustrates computing concepts, and can be used in classroom explanations or programming assignments.

In this paper we present several magic tricks and programming exercises that students can complete to implement these tricks and explore these phenomena. Starting from the two tricks discussed above that we will demonstrate, we will include a list of resources:

1. The magic square example given in the demonstration: which includes a link to play it online at

2. A variation of the demonstrated “Six Boxes” problem is at

3. Card grid used to illustrate error-detecting codes:
a. Inspired by
b. Play online at:
c. Additional extensions and online implementations available at

4.Transitive dice, where no matter which die your opponent chooses, your choice beats theirs on average:

5. Replicating card tricks in a computer program (and many more excellent ideas) at See also

6. Guess a number, and the computer will find it:
b.Choose a number between 0 and 50,000, and the computer guesses it using a technique known as "binary search".

7. Many AI or pattern-matching programs can seem like magic, such as Google’s QuickDraw or 20 Questions. See if the computer can out-guess you in a simple 0/1 guessing game, playing online at:
Magic, Programming, STEM, Binary, Parity, Search, Card, Number Guess, Dice.