Fundamentals 10 min read

Recreating Liu Qian’s 2024 Spring Festival Gala Magic Trick Using Go

This article walks through a step‑by‑step Go implementation of Liu Qian’s 2024 Spring Festival Gala magic trick, explaining how to model the card‑handling algorithm with slices, shuffle, cuts, and loops, and provides complete source code and execution logs for readers to try.

Go Programming World
Go Programming World
Go Programming World
Recreating Liu Qian’s 2024 Spring Festival Gala Magic Trick Using Go

The 2024 Spring Festival Gala featured Liu Qian’s magic trick "Guard the Year Together"; this article demonstrates how to reproduce the entire trick using the Go programming language.

Before coding, a humorous "crash" image is shown. The trick is essentially a Josephus‑type problem, but the focus here is on implementing the fixed routine with Go.

Step 1 – Prepare four playing cards and shuffle them.

// We use an int slice `pokers` to store the cards
var pokers []int = []int{2, 7, 6, 5}

// 1. Shuffle the slice randomly
rand.NewSource(time.Now().UnixNano())
rand.Shuffle(len(pokers), func(i, j int) { pokers[i], pokers[j] = pokers[j], pokers[i] })
fmt.Printf("1. Shuffled cards: %v\n", pokers)

The shuffled result might be [6 7 5 2] .

Step 2 – Double the deck by appending the slice to itself.

pokers = append(pokers, pokers...)
fmt.Printf("2. After doubling: %v\n", pokers)

Result: [6 7 5 2 6 7 5 2] .

Step 3 – Move a number of cards from the top to the bottom based on the length of your name.

pokers = append(pokers[2:], pokers[:2]...)
fmt.Printf("3. After moving name‑length cards: %v\n", pokers)

Result: [5 2 6 7 5 2 6 7] .

Step 4 – Take the top three cards and insert them at an arbitrary middle position.

pokers = append(pokers[3:7], pokers[0], pokers[1], pokers[2], pokers[7])
fmt.Printf("4. After inserting three cards: %v\n", pokers)

Result: [7 5 2 6 5 2 6 7] .

Step 5 – Remove the top card and keep it secret.

top := pokers[0]
pokers = pokers[1:]
fmt.Printf("5. Removed top card: %d, remaining: %v\n", top, pokers)

Now top = 7 and pokers = [5 2 6 5 2 6 7] .

Step 6 – Depending on regional preference, take 1, 2, or 3 cards from the top and re‑insert them. (Assuming a northern audience, we take 2 cards.)

pokers = append(pokers[2:6], pokers[0], pokers[1], pokers[6])
fmt.Printf("6. After regional cut: %v\n", pokers)

Result: [6 5 2 6 5 2 7] .

Step 7 – Gender‑based removal: males drop one card, females drop two. (Assuming male.)

pokers = pokers[1:]
fmt.Printf("7. After gender removal: %v\n", pokers)

Result: [5 2 6 5 2 7] .

Step 8 – The “miracle” loop: repeat the operation of moving the top card to the bottom for each character of the phrase "见证奇迹的时刻" (seven characters).

for range []string{"见", "证", "奇", "迹", "的", "时", "刻"} {
    pokers = append(pokers[1:], pokers[0])
}
fmt.Printf("8. After miracle loop: %v\n", pokers)

Result: [2 6 5 2 7 5] .

Step 9 – Final ritual: "good luck stays, worries go". For a male, perform the good‑luck move five times and discard the top card each time.

for range []int{1, 2, 3, 4, 5} {
    // good luck stays
    pokers = append(pokers[1:], pokers[0])
    // worries go
    pokers = pokers[1:]
}
fmt.Printf("9. Final result: %v\n", pokers)

The slice now contains a single element: [7] , which matches the hidden card kept earlier.

Verification:

fmt.Printf("Witness the miracle: %d == %d", top, pokers[0])

Output: Witness the miracle: 7 == 7 .

The complete program log is shown, confirming each step’s intermediate state.

All source code is available on GitHub, and readers are encouraged to modify the sixth step (the “Niger Maite” mishap) to see the effect.

Contact information and references are provided at the end of the article.

AlgorithmProgrammingGotutorialsliceDemoMagic Trick
Go Programming World
Written by

Go Programming World

Mobile version of tech blog https://jianghushinian.cn/, covering Golang, Docker, Kubernetes and beyond.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.