Categories
Mathematics

Why Chutes and Ladders, Why?!?

Chutes and Ladders (or Snakes and Ladders in some parts?) is a children’s board game where the goal is to make your way through 100 squares/spaces to the end of the board first. If you’re not familiar, look up an image of the game board to get an idea.

As a player, the strategy is to … oh wait, you just spin the wheel, don’t think at all, and move squares. More specifically you spin an integer between 1 and 6, move that many squares, follow chutes or ladders, and repeat until finished. There is literally no strategy or decision making in the entire game.

This makes the game pretty strategically boring, but also very amenable to statistical analysis. And honestly, my main gripe with the game isn’t the boredom, it’s that it seems to have the potential to take way more turns than is appropriate for a game that claims to be for 3-year-olds.

And so, let’s model Chutes and Ladders!

First things first, we can construct a transition matrix that describes the probability of landing on any square given a starting square. The spinner has equal chance of getting the integers 1 – 6. If you land on a normal square, you stay there and if you land on the start of 1 of the 10 chutes (which move backward on the board) or 1 of the 9 ladders (which move forward on the board) we’ll say you instead wind up on the end of the chute/ladder. You always leave the first square (number 0) and can never return to it. Conversely, if you land on the last square (number 100), you’ll never leave.

So we can construct a \( 101 \times 101 \) matrix where each entry \( T_{ij} \) is the probability of starting on square \( i \) and ending on square \( j \).

Image showing the Chutes and Ladders transition matrix. White is probability-zero and black is probability-one. Looking at a row tells you the squared you might land on starting from the square that has that row’s index.

Using this transition matrix, one nice thing to compute is the probability of being on the different squares at each turn (for just 1 player). We can start with a probability vector that had probability 1 on the start square and “taking a turn” corresponds to multiplying the vector by the transition matrix

\( p_{t+1} = p_t \cdot T \).

We can iterate many times and see what the distribution looks like.

GIF of the probability of being on each square as a function of the turn number. You may need to click on the image to make the animation go.

I made the probability of being on square 100 (done with the game) in red on the right. As a parent, it concerns me how slowly this bar rises after about turn 10 … just hanging out below 0.2. This is a game for 3 year olds!

Another view of this is to ask: how long does it take to win the game? What does this distribution of game times look like? We can also use the transition matrix to simulate games, not just update probability distributions. If we simulate 10,00 chutes and ladders players, we can plot how many games take \( N \) turns or more. We can also track \( 1 – p(100) \) from the animation (1 minus the red bar value) and these should agree.

Simulation (blue histogram) and exact computation (black line) of game length distribution for single players.

Something like 10% of games take 75 turns. Oof. It’s worse when 4 players are playing and you think about how long it takes the last player to finish.


Simulation (blue histogram) and exact computation (black line) of game length distribution for 4 players.

Now 10% of games take 100 turns for all players to finish. Maybe it’s just me, but I feel like if you’re designing games for 3-year-olds, you have some responsibility to run a handful of Monte-Carlo simulations to get a sense of how laborious getting through an entire play-through will be.

Categories
Data Analysis Machine Learning

Markov chains are all you need (to write bad Christmas songs)

Large language models (LLMs) are all the rage these days. They can write (occasionally buggy) code, help you write generic-sounding prose quickly…but can they write ungrammatical Christmas songs? Call me a Luddite, but I’m skeptical.

Luckily, there is a language model out there that doesn’t require 1TB of GPU RAM and a nuclear-reactor-enabled-data-center to .eval(). In fact, with a little determination, you could probably run it natively in a spreadsheet…or on pen-and-paper.

That’s right, I’m talking about Markov chains (of the first order).

But remember when you gave it must be
Let's lay here tonight
But it's a rock
Where the old and the old and that's not a new year
Sure did see mommy kissing santa comes around the mistletoe hung by the king pa rum bu bum
We all year i'll give us annoyed
And i want for christmas christmas is coming to need you better be glad you're sleeping
You my wish come
And a beard that's past
We wish you baby
I'll have a crowded room friends on his sled
Must be

Markov chains are a simple yet ubiquitous probabilistic model that assumes that the probability of what happens next only depends on what is happening now. For a language model, this means that the probability of what word (or token if you’re a nerd) comes next only depends on what the current word is. If we run this process repeatedly, word-after-word, we get things resembling sentences.

I can’t say I’m a huge fan of Christmas pop/rock songs (but I can evaluate it’s likelihood). However, I also think they are corny.

Guide us some decorations of dough
She didn't see
And practicing real famous cat all your soul of mouths to see me
I've got it over
Underneath the jingle bell time for you will you dear if you cheer
You gave you and bright
The very merry christmas girl
Jingle bell jingle bell rock the halls
Let love you dismay
I want it felt like i'm watching it over again
So long long distance
It's lovely weather for christmas all year it always this christmas to succeed

But I don’t want to deal with “gradients” or “descent” or the latest attempt to retcon RNNs (I prefer my BPTT to run sequentially and then vanish…or explode). In the words of Todd Rundgren: “I don’t want to work, I just want to” histogram some lyrics I copied off the internet.

So. I downloaded the lyrics to 30-some pop/rock Christmas songs, fired up a jupyter notebook, deleted some punctuation, and (with a mere 1 vector and 1 matrix) started generating lyrics and posted them here.

Side note: AC/DC released a Christmas song titled: “Mistress for Christmas” in 1990 about Donald Trump cheating on his wife. I had no idea.

You baby
I'm watching it from tears
'cause i believed in trouble out you guys know what time i know
And unto certain
Ding dong
Oh my bedroom fast asleep
A merry-go-round
You and cheer
A beard that's white
I thought you gave you make us some money to the halls
Don't want to set before the world will share this one
Hurry tell him hurry down

Mostly..what I’ve learned…is that Christmas songs are weird and often not really about Christmas at all. I’ll post the data and code soon so that you too can generate bad Christmas lyrics using AI.

My bedroom fast asleep
Ho ho
She got it
You've really can't stay
Oh what a happy new year i'll have termites in trouble out there all over now i've missed 'em
The window at a poor boy child what have some magic reindeer to thy perfect light shine on a button nose
So i thrill when you a cactus
This tear
I'll give all need love breathe
I'll give it to someone
I wouldn't touch you have fun if you want it as opportunistic
The mistletoe last year to town