A Magic Trick Using The SET Deck: Zhengyu Li
A Magic Trick Using The SET Deck: Zhengyu Li
A Magic Trick Using The SET Deck: Zhengyu Li
Zhengyu Li
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 1 / 25
Table of Contents
2 Trick Demonstration
4 De Bruijn Graphs
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 2 / 25
Table of Contents
2 Trick Demonstration
4 De Bruijn Graphs
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 3 / 25
Quick Introduction of SET
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 4 / 25
Quick Introduction of SET
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 4 / 25
Quick Introduction of SET
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 4 / 25
Quick Introduction of SET
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 4 / 25
Table of Contents
2 Trick Demonstration
4 De Bruijn Graphs
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 5 / 25
Trick Demonstration
A SET Deck
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 6 / 25
Table of Contents
2 Trick Demonstration
4 De Bruijn Graphs
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 7 / 25
De Bruijn Sequences and Its Special Properties
Definition
A de Bruijn sequence is a cyclic sequence of a given alphabet A with size
k, for which every possible subsequence of length n in A appears as a
sequence of consecutive characters exactly once. We denote a de Bruijn
sequence as B(k, n).
Example
For example, one element of B(3, 3), using alphabet {0, 1, 2}, is
021112120002011001221010222.
You can check that each of the 27 strings of length 3 from the alphabet
{0, 1, 2} appear once and only once as a consecutive subsequence (note
that 220 and 202 start at the end and wrap around).
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 8 / 25
Table of Contents
2 Trick Demonstration
4 De Bruijn Graphs
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 9 / 25
De Bruijn Graphs
One way to build de Bruijn sequences (and thus prove their existence)
comes from graph theory.
Definition
Let A be an alphabet with k elements. The de Bruijn graph G (k, n) is a
directed graph with k n–1 vertices labeled with all possible strings of length
n–1 from A. For each vertex v , labeled a1 a2 . . . an−1 , and each element d
of A, there is a directed edge (labeled d) from v to the vertex labeled
a2 a3 . . . an−1 d. In particular, we have an edge labeled d from vertex v to
vertex w if the label on w can be obtained by appending d to the label on
vertex v with the first character removed.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 10 / 25
De Bruijn Graphs of G(3,3)
Definition
An Eulerian circuit or Eulerian cycle is a
trail in a finite graph that visits every
edge exactly once and starts and ends on
the same vertex.
Traversing through an Eulerian circuit
will give us a de Bruijn sequence.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 11 / 25
De Bruijn Graphs of G(3,3)
Example
One Eulerian circuit in G (3, 3) is given
by the vertex sequence 22 → 20 → 02 →
21 → 11 → 11 → 12 → 21 → 12 →
20 → 00 → 00 → 02 → 20 → 01 →
11 → 10 → 00 → 01 → 12 → 22 →
21 → 10 → 01 → 10 → 02 → 22. When
we read off the labels of the associated
edges in order, we obtain the de Bruijn
sequence from B(3,3) previously
mentioned:
021112120002011001221010222.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 12 / 25
Table of Contents
2 Trick Demonstration
4 De Bruijn Graphs
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 13 / 25
A Special De Bruijn Sequence for the SET Deck
Consider the alphabet A = {0, 1, 2}. We can interpret each SET card as a
string of length n = 4 over the alphabet A, which has k = 3 elements. The
following table provides a mapping between such strings and SET cards.
Provide context to alphabet A
For instance, the string 0000 refers to the card with three, purple, striped
diamonds
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 14 / 25
A Special De Bruijn Sequence for the SET Deck
Using this encoding, any de Bruijn sequence from B(3, 4) allows us to read
off (cyclically) all 81 consecutive subsequences (from left to right)
producing an order of the deck necessary to perform our trick.
Based on this construction, every four consecutive digits of the sequence
provide full information for one card and partial information for the three
cards after it.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 15 / 25
A Special De Bruijn Sequence for the SET Deck
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 16 / 25
A Special De Bruijn Sequence for the SET Deck
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 16 / 25
A Special De Bruijn Sequence for the SET Deck
It turns out that there are some de Bruijn sequences with nice algebraic
properties, giving us an ability to “predict” the sequence beyond a given
substring in order to perform the trick without needing to memorize all the
terms of the sequence.
Definition
We define our de Bruin sequence B = (0, 0, 0, 1, B5 , B6 , . . . , B81 ) where Bn
(for n > 4) is obtained recursively by Bn−3 + Bn−4 (mod 3). Thus, given
any consecutive substring of the form Bn Bn+1 Bn+2 Bn+3 , the next entry
Bn+4 is the remainder of the sum Bn + Bn+1 when divided by 3.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 17 / 25
A Special De Bruijn Sequence for the SET Deck
We will start with 0001, then the fifth digit is 0 + 0 (mod 3) = 0, the
sixth digit is 0 + 0 (mod 3) = 0, and the seventh digit is 0 + 1
(mod 3) = 1. By continuing this recursive process, we end up with a
complete de Bruijn sequence of length 81:
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 18 / 25
Table of Contents
2 Trick Demonstration
4 De Bruijn Graphs
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 19 / 25
Preparation
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 20 / 25
Preparation
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 20 / 25
Performance
The magician cuts the deck repeatedly (since it is cyclic, the property
of de Bruijn sequence remains).
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 21 / 25
Performance
The magician cuts the deck repeatedly (since it is cyclic, the property
of de Bruijn sequence remains).
The magician hands out four consecutive cards to four volunteers.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 21 / 25
Performance
The magician cuts the deck repeatedly (since it is cyclic, the property
of de Bruijn sequence remains).
The magician hands out four consecutive cards to four volunteers.
The magician asks ”Which feature would you four like to describe?”
Let us assume the volunteers choose shape.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 21 / 25
Performance
The magician cuts the deck repeatedly (since it is cyclic, the property
of de Bruijn sequence remains).
The magician hands out four consecutive cards to four volunteers.
The magician asks ”Which feature would you four like to describe?”
Let us assume the volunteers choose shape.
The magician then asks ”Would all of you holding the diamond please
raise your hand?” Let us assume the third person raises their hand.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 21 / 25
Performance
The magician cuts the deck repeatedly (since it is cyclic, the property
of de Bruijn sequence remains).
The magician hands out four consecutive cards to four volunteers.
The magician asks ”Which feature would you four like to describe?”
Let us assume the volunteers choose shape.
The magician then asks ”Would all of you holding the diamond please
raise your hand?” Let us assume the third person raises their hand.
The magician asks ”Now, would everyone with an oval please raise
your hand?” Let us assume the first and fourth person raise their
hand.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 21 / 25
Performance
The magician cuts the deck repeatedly (since it is cyclic, the property
of de Bruijn sequence remains).
The magician hands out four consecutive cards to four volunteers.
The magician asks ”Which feature would you four like to describe?”
Let us assume the volunteers choose shape.
The magician then asks ”Would all of you holding the diamond please
raise your hand?” Let us assume the third person raises their hand.
The magician asks ”Now, would everyone with an oval please raise
your hand?” Let us assume the first and fourth person raise their
hand.
The magician correctly name all four cards in order, including their
numbers, colors, shadings, and shapes.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 21 / 25
Trick Reveal
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 22 / 25
Trick Reveal
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 22 / 25
Trick Reveal
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 22 / 25
Trick Reveal
Bi+6 − Bi+3 = 1 − 1 = 0, so
Bi+2 = 0
Bi+5 − Bi+2 = 0 − 0 = 0, so
Bi+1 = 0
Bi+4 − Bi+1 = 2 − 0 = 2, so
Bi = 2
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 23 / 25
Trick Reveal
Bi+6 − Bi+3 = 1 − 1 = 0, so
Bi+2 = 0
Bi+5 − Bi+2 = 0 − 0 = 0, so
Bi+1 = 0
Bi+4 − Bi+1 = 2 − 0 = 2, so
Bi = 2
Thus, we have an entire length
seven subsequence of the form
2001201, from which we can read
off the algebraic representation of
each card in order.
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 23 / 25
Trick Reveal
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 24 / 25
Wrap Up and Further Reading
Li, Zhengyu (UTM) A Magic Trick Using the SET Deck August 2020 25 / 25