The beauty of math

My son and I love to play Keyforge, a fascinating card game. Each of the two players has a unique deck containing 36 cards, 12 cards from 3 "houses".

The beauty of math
Photo by vackground.com / Unsplash

My son and I love to play Keyforge, a fascinating card game.

Each of the two players has a unique deck containing 36 cards, 12 cards from 3 "houses". Like in most card games, there's an element of randomness that makes the game more exciting and can decide the outcome. In one of our duels, we came across this card, called Ransack:

The Ransack card from the house Shadows. Discard the top card of your deck. If that card is a Shadows card, trigger this effect again.
The Ransack card from the house Shadows

The card gives you at least one æmber (the currency in the world of Keyforge) by stealing it from your opponent, but it can give you more. If your next card you draw is also a Shadows card, it gives you two - if your 3rd card also shares that house, it gives you three, and so on.

So how many æmbers do you usually win? In mathematical terms, what is the expected value of the number of æmbers gained?

Well, each time you draw a card, you have a 1/3 chance of drawing a Shadows card. The probability of drawing two Shadows card in a row is 1/3 * 1/3 = 1/9. To do so three times, the probability is 1/27, and so on. So the expected value of the number of æmbers gained is:

e = 1 + 1/3 + 1/9 + 1/27 + 1/81 + ...

This calculation is not entirely accurate as the deck doesn't have an infinite number of cards, and it matters a lot how many cards you have left in the card and how many Shadows cards are left among the cards you draw from. That's fine, though, we don't want a super precise result, and at this point, I'm more interested in finding a way to calculate the above sum :)

Now comes the mind-blowingly nifty trick that I learned from someone when I asked a question about this card on Discord.

Let's divide both sides of the equation by 3:

e / 3 = 1/3 + 1/9 + 1/27 + 1/81 + ...

However, we know from our first, original formula that the right side of this equation equals $e - 1$ so substituting this gives us the following:

e / 3 = e - 1

We've eliminated the infinite sum and reduced it to a primary school equation. Solving it gives us the expected value:

e = 3/2

We might notice that the formula is quite straightforward to generalize. If we denote the number of different outcomes for each draw as n , our expected value becomes:

e = 1 + 1/(n-1)

So if each deck in Keyforge had 4 houses, the expected value of the number of æmbers you win with Ransack would be 4/3.

Whenever I come across something similar, I feel like I should "do" more math: it's a thing of pure beauty, untainted by messy reality.