Using Magic to Teach Computer Programming

Dale F. Reed, Ronald I. Greenberg

Research output: Contribution to journalArticlepeer-review

Abstract

Magic can be used in project-based instruction to motivate students and provide a meaningful context for learning computer programming. This work describes several magic programs of the “Choose a Number” and “Pick a Card” varieties, making connections to underlying computing concepts.

Magic tricks presented as demonstrations and programming assignments elicit wonder and captivate students’ attention, so that students want to understand and replicate the work to show it to friends and family members. Capturing student interest and curiosity motivates them to learn the underlying programming concepts.

Two “Choose a Number” programs are shown where the computer is able to identify a user’s choice among many alternatives:

1. Magic Letter: A table of numbers with associated random letters is displayed. Participants make choices and the computer identifies their chosen letter.

2. Number Boxes: The user chooses a secret number, for example the age at which their business becomes successful and is sold. The user indicates which boxes displayed on the screen contain the secret number, and the computer then identifies the number.

Two “Pick a Card” varieties are shown, where board pieces represent cards, the user selecting one of them that the computer later identifies:

1. Secret Tile: A grid of black and white tiles is displayed, where the computer verifies that the magician can identify which secret tile selected by a volunteer has been flipped.

2. Twenty-one Card Magic: Twenty-one cards are selected from a shuffled deck and displayed faceup, with a volunteer choosing a secret card. After repeated stacking and re-dealing, the secret card is identified.

These examples illustrate computing concepts and can be used in classroom explanations and programming assignments. Links are given to online playable versions, assignment descriptions, and magic-themed resources in computing.

Original languageAmerican English
JournalComputer Science: Faculty Publications and Other Works
DOIs
StatePublished - Jul 5 2022

Keywords

  • Magic
  • Computer Programming
  • STEM education
  • Binary
  • Parity
  • Search
  • Number Guess

Disciplines

  • Computer Sciences
  • Discrete Mathematics and Combinatorics
  • Other Computer Sciences
  • Other Education

Cite this