cards27

Project Description

This is a simple Snap implementation of the classic 27-card trick, written to show the math behind the trick instead of just the effect.
The program uses lists and ask blocks (no graphics) as a quick proof-of-concept while learning how Snap handles user input and lists.

The trick works by repeatedly dealing 27 cards into 3 piles, asking which pile contains the chosen card, and gathering the piles again. After three rounds, the chosen card always ends up in the location entered at the start.

The reason this works is that the trick is really based on base-3 (ternary) arithmetic.

If the chosen position is N, we first use:

N − 1

and convert that number to base-3.

Example:
Favorite number = 20

20 − 1 = 19
19 = 201 (base 3)

The ternary digits determine how the piles must be gathered at each round.
Because the first deal corresponds to the least-significant digit, the digits are used in reverse order:

201 → 1, 0, 2

Each digit tells where the chosen pile goes when gathering:

0 = top
1 = middle
2 = bottom

After three rounds the card is forced to the desired location, which is why the trick always works.

This version keeps everything text-based for simplicity, but it could be extended later to a graphical card layout.

this youtube video inspired me to make a verison in snap                                               https://www.youtube.com/watch?v=l7lP9y7Bb5g&t=275s                                                                                 

Created March 22, 2026

Last updated March 24, 2026

Published March 24, 2026

Public collections containing this project