Today’s post is a bit unusual for me — it’s very pragmatic and not about reflections at all.
I have a favorite story of how math once helped me elegantly solve a problem. Imagine you’re a game designer planning an event. You want to create complex conditions for a contest: the gacha mechanic always works, but it works better if the player fulfills these conditions. The rules are: the gacha can always be opened if the player gives 2 to 6 tokens of different colors. With 2 tokens the gacha is more predictable; with 6 it’s less predictable. But you also want to create “boosted chance combinations,” about a dozen per month, that should overlap as little as possible.
For example, the player gives you red, blue, green and brown tokens — and their chance to get rewards increases compared to the resources they spent. And on three days of the month you also encourage using orange, yellow and purple tokens, as well as green, blue, white, black and light blue.
The question: how do you make sure no combination of colors is fully contained in another? How do you avoid having both “red, white and green” and “red, white, green and black”? With 2–3 combinations you can compare them manually. But what if you have 10, 50, 500? (I had about 50.)
Prime numbers to the rescue. Here’s the magic: red = 2, orange = 3, …, black = 29 (the tenth prime). Now any set of colors can be encoded into a unique composite number by multiplying all elements together. Red, orange and black would give you 2×3×29 = 174. Now you just assign each color combination these numbers and check that no number divides another without a remainder — because that only happens when all factors of one are also factors of the other.
It’s not a problem you need to solve every day, but since then I’ve used prime numbers for encoding elements a few more times, and every time it made automation so much easier.
And if you bend a paperclip into the shape of an integral sign, you can fish out keys dropped into a toilet — so math often turns out to be surprisingly useful in everyday life.