Welcome to the fifteenth match in this year’s Big Math-Off. Take a look at the two interesting bits of maths below, and vote for your favourite.
You can still submit pitches, and anyone can enter: instructions are in the announcement post.
Here are today’s two pitches.
Colin Beveridge – The Young Rowlett’s Robot Caterpillar
Colin blogs at flyingcoloursmaths.co.uk and tweets at @icecolbeveridge.
Weymouth has one of the finest cycle networks of any medium-sized town in the southwest of England.
I stopped my run mid-stride, almost falling onto a cyclepath. Peter Rowlett, in an episode of Mathematical Objects, had just invoked the dread incantation: generating functions.
I do not use the phrase ‘dread incantation’ lightly. Generating functions are one step removed from dark magic, and it immediately became my mission to use them to solve the Robot Caterpillar Problem.

Peter’s son has – or, I should say, had – a toy robot, comprising a head and eight attachments. The attachments can be arranged in any order: three that cause the robot to move forward, two that turn it left, two that turn it right, and one (in a twist I’m sure is entirely unconnected to the fact that the robot no longer works) that plays a jaunty tune. Any number of segments between one and eight (inclusive) constitutes a valid robot. The packaging claims the number of arrangements is “endless”; Peter believes the number to be… well, endful. But how many exactly?
A brief explainer on generating functions
Before you get onto the robot’s generating function, I’m going to start with an example that’s a bit less complicated.
Consider the binomial expression
Consider also the binomial distribution. Given
For a polynomial generating function to correspond to a probability distribution, the coefficients must be non-negative and
The binomial expression
It’s not just for probability distributions, though: it’s also for counting problems. Like, to pull an example out of thin air, the number of ways to arrange the segments of a robot.
Generating a robot
The approach Peter and Katie suggest in the podcast is to figure out the possible combinations of pieces using a generating function in four variables:
- Represent the possible number of forward pieces as
– since you can use 0, 1, 2 or 3 forward pieces; - Represent the possible number of left pieces as
– since you can use 0, 1 or 2 left pieces; - Represent the possible number of right pieces as
; - Represent the possible number of music pieces as
.
If you listened to the podcast, you’ll know that this gives all of the possible combinations plus one impossible one: the caterpillar’s head needs at least one segment attached to it if you want it to work. I’m going to ignore that fact until much later.
… and multiply all of those together. Each term of the resulting polynomial has either zero, one, two or three
However, they turn up without respect to order – so, for example the term
Yes, I know it can be a short script in Python. Where’s the fun in that?
I don’t know about you, but I didn’t spend seven years at dark magic school to do grunt work like that. We have a Wolfram|Alpha for doing grunt work. The only question is, how to set up the problem so that Wolfram|Alpha gives us the answer?
First insight: dividing out repeated segments
If a combination of segments has
Rather than do that manually every time, why not build it in to the generating function? Instead of representing the number of forward pieces by
That would turn the term that used to be
Second insight: who needs all of those letters?!
Now you’ve accounted for all of the repeats, it doesn’t really matter (for counting purposes) what the pieces are – only the degree of the term involved. That means, if you replace all of the variables with
The generating function is now
All you have to do is replace each degree-
That’s still boring, though. There must be a way to do that automatically, mustn’t there?
Of course there is.
Third insight: operational calculus
There’s a trick, in generating functions: if you want to multiply each of the degree-
However, there’s a problem: if you do that, all of the lower-order terms vanish, and that’s not what you want at all. Also, if you differentiate, say, six times, your unit term is the correct number of six-segment permutations, but you still have an
To find the total number of possible robots, you need to sum the first eight derivatives of
That is to say, you want
Thanks to Akiva Weinberger for helping me get this ironed out.
Let’s use
(D) is an operator, but I’m treating it as a variable here. This is Very Naughty and @realityminus3 will have my head on a stick. It can be made rigorous… I trust.
Everybody knows that
That can be solved using an integrating factor:
- So
Finishing off
That’s not something that’s especially nice to work out by hand (in effect, you have to do all of the differentiation you were trying to avoid) – but Wolfram|Alpha doesn’t mind!
If you scroll down to the expanded form, it gives
Removing the one case where there are no segments gives 5023, which is the answer Peter gave on the podcast. Alakazam!
Peter Kagey – Counting Stacks
Peter writes about maths at peterkagey.com and tweets at @PeterKagey.
One of the most surprising combinatorial formulas I know is also one of the simplest. It arises when counting stacks of

Here’s the miracle: If you have
Usually when some set of objects is counted with such a simple formula, there’s an easy explanation. In this case, for example, you might expect that there are always exactly three ways to add a new block onto an existing stack. Curiously, there’s not such an easy explanation.
The Four Rules
There are four rules that these stacks of bricks must follow. (Below the list, you can find examples of stacks that break each of these rules.)
- The bricks must lie in a vertical plane.
- Each brick must be offset by 1 stud, like you might see in a brick wall.
- The bottom layer must be contiguous.
- Every brick must have at least one brick below it.
This means that the following four stacks are not allowed:




An example for three bricks.
When building with three bricks, there are









A proof
This result was first proven in a 1988 statistical mechanics paper, but the nicest proof that I know of can be found in Miklós Bóna’s book (page 26). Bóna’s proof uses decomposes the stacks of blocks in a clever way and then uses a bit of generating function magic. (Generating functions are a tool in combinatorics which is usually first encountered at the beginning of graduate school.)
Uncharted territory
By removing or modifying any of the four rules, you get new kinds of stacks with different formulas. For example, if you remove the second rule, there are
Here’s where you come in! If you’d like to do a bit of original mathematics, choose some set of rules and count up the number of resulting stacks for small numbers of blocks. Even better, find a formula for the number of stacks!
These counts would make a great addition to the On-Line Encyclopedia of Integer Sequences. If you’d like to do this, but feel intimidated or don’t know where begin, I’d love to do it together with you––just let me know on Twitter (@PeterKagey)!
So, which bit of maths made you say “Aha!” the loudest? Vote:
Match 15: Colin Beveridge vs Peter Kagey
- Peter with stacks of LEGO bricks
- (76%, 34 Votes)
- Colin with robot caterpillars
- (24%, 11 Votes)
Total Voters: 45
This poll is closed.

The poll closes at 9am BST on Monday the 11th, when the next match starts.
If you’ve been inspired to share your own bit of maths, look at the announcement post for how to send it in. The Big Lockdown Math-Off will keep running until we run out of pitches or we’re allowed outside again, whichever comes first.
2 Responses to “The Big Lock-Down Math-Off, Match 15”