## Quantum Gambling Game

Have you ever heard of quantum computing? Know what makes it so special? Well, many scientists (and their funding agencies) are hoping that quantum computing's secrets just might help get them rich.

I can't promise you that. But I can share this quantum gambling game I made with you. Although it looks simple enough on the surface, this betting game actually reveals an interesting application of quantum computing, the science turning "spooky" physics into solving real problems.

I'll explain more about strategy and its relation to quantum algorithms below, but for now, try the game out! Read below for more instructions.

#### Instructions

The goal is to get the biggest bet you can onto the Ace of Spades, and to keep your bet off of the decoy cards. But the trick is that during the game none of the cards are ever revealed to you.

You start the game by placing your initial bets on whatever cards you want.

After that, you have your choice of two moves, which you get to repeat until you decide you're done.

1. Trade Bets, meaning any money on the losing cards goes to the dealer, while the money on the winning card stays the same.
2. Redistribute, meaning you reverse all the bets around the average bet value. So the dealer's money comes back to your side of the average, and vice versa.

The redistribute move might seem confusing, so here's what it does graphically.

During the redistribution, the dealer basically just moves the money around so that places where the money is on the dealer's side shift back to places where you still have money. The math can get really complicated based on how many different bets there are going, but it boils down to just flipping the bets like in the graphic.

Throughout the game, all the money stays on the table. But unfortunately for you, even though the money is changing hands, the dealer never tells you whether a given bet is yours or his on the table.

Whenever you want, you can end the game. At that point, the dealer checks how much money there is on the winning card and gives you back two times that amount. He takes everything else.

#### Some Quantum Hints

OK, so you're stumped. Here are some hints.

I mentioned that it's possible to win every time—not just most of the time. That should be a clue that the game doesn't rely on guessing.

A second clue to point out is that the Trade Bets operation "undoes itself." That means that if you Trade Bets twice in a row, that's the same thing as not trading bets at all. Take a minute to understand why that's true.

Finally, I'll just tell you that repeating the Redistribute operation twice in a row isn't necessary to solve the problem.

If you really don't have any idea what I'm talking about, check out this appendix at the bottom of the page for more info.

Now give it another try.

#### Time out: how is quantum computing supposed to help me?

For quantum computing, it's all about using fewer iterations to get the same job done. A quantum algorithm aims to take a problem that would take billions of calculations on a classical computer and turn it into just hundreds of quantum calculations.

For example, how long could it take you to find the card by guessing in the classical world? If there are 8 cards you could have to guess 8 times. But for the quantum algorithm on which this game is based, you would be guaranteed to find the card with just 2 guesses. How does it do that? Well, you'll have to read on to find out.

But with the 2 repetitions in mind, try the game out again.

#### How to win the Game

The way to win every time starts with eliminating all guessing. What I mean by "no guessing" is that the initial configuration of bets must be the same for every card. For example, you can just bet 1 on each card.

After this we just start trying operations. Because Redistributing on all 1s doesn't change the bet values, we know that we start by Trading Bets with the dealer and then we Redistribute. We could redistribute over and over, but it turns out that won't help (although I don't know why. If you know, put it in the comments). At this point, we just have to toggle back and forth between Trading and Redistributing operations.

If we repeat those operations just the right number of times, our initial bets will work their way onto the winning card. Now we just need to figure out how many times to repeat those moves.

It turns out that the right number of repetitions is two. There's a reason that you have to repeat the pair of operations exactly twice, but I have to wait until after I explain the quantum mechanics to get to that. For now, just try playing it again and show yourself that it actually does work.

#### Quantum Information and Grover's Algorithm

The two moves in the game are really just classical ways to describe more "spooky" operators from quantum computing. And the money gained at the end of the game is analogous to your probability of finding a solution to the problem using a search algorithm.

The Trading Bets operation would be called a Quantum Oracle, which by itself doesn't tell you which solution is right, but will confirm if you have the right answer at the end (by giving you money or taking it). And the Redistribute move is a Grover Diffusion Operator, which essentially lets information about the correct answer "diffuse" from wrong answers. (Note that this is way more complicated than I can explain, and to understand it for real you might need to do more reading (or even take a class) on the subject.)

When you repeat these two operations back to back, you end up performing Grover's Algorithm, a technique proven to find the right information in a database (i.e. the cards). Lov Grover (not Love, Grover) discovered this way of finding information back in the 90s. He was working on a method to compute inverses by letting a quantum function (i.e. the dealer) perform operations (i.e. Trading Bets) that we couldn't see in the classical world (i.e. on our side of the betting table). What was amazing about it was that it allowed you to perform the calculation many fewer times than you would using a classical (asking "Hey, is it that card?") approach.

In the above game, you only need to repeat the procedure 2 times. Whereas to find the card by guessing, you might have to try 8 times. If you want to learn more about why it's exactly 2, I recommend this in depth article on the subject.

(And to learn more about Grover's algorithm with cool visualizations, check out this tutorial from Twisted Oak Studios.

#### So what's the big deal?

In the end, what's really important about Grover's algorithm is that this isn't just a mathematical artifact. The crazy laws of quantum mechanics somehow make it possible to perform these operation on real materials. This means that it can be used to find real answers to questions that we can't solve fast enough with current computers.

Unfortunately, building quantum computers is turning out to be insanely hard so currently we can still do better with classical computers. But hopefully someday soon, a big breakthrough will make this technology possible.

#### Playing more with quantum computers

If you want to work more on this, feel free to check out my code. For starters, you can find the javascript for the game on CodePen here. If you're more interested about the quantum details, you can also check out this project on Github that implements quantum computing gates as MATLAB matrix operations.

.
.
.

#### Appendix: Basic Primer on the Quantum Betting Game

In case you need a little background about betting and guessing games, here's a little Appendix that will help fill you in.

### Discussion Around the Web

Join the Conversation