About a year ago or so, I created a math problem and submitted it to CsTutoringCenter. Titled *Stepping Stones*, my problem statement went like this:

In a certain river, there are a bunch of stepping stones arranged from one side to the other. A very athletic person can cross the river by jumping on these stepping stones, one at a time.

A stepping stone is big enough for only one person, and the gap between two stepping stones is small enough that it is possible to jump between two adjacent stepping stones.

You are an army commander trying to get a group of soldiers across this river (using these stepping stones). Initially your n soldiers are placed on the first n stepping stones. Your task is to get all of them onto the last n stepping stones.

For example, here are the five possible ways to get a group of two soldiers across a river with five stepping stones:

1) ##--- #-#-- -##-- -#-#- --##- --#-# ---## 2) ##--- #-#-- -##-- -#-#- -#--# --#-# ---## 3) ##--- #-#-- #--#- -#-#- --##- --#-# ---## 4) ##--- #-#-- #--#- -#-#- -#--# --#-# ---## 5) ##--- #-#-- #--#- #---# -#--# --#-# ---##Let C(k,n) be the number of ways of which n soldiers can cross a river with k stepping stones. In the example, C(5,2) = 5.

Find C(50,12) mod 987654321.

Of course, small values of may be bruteforced by a computer. But is well out of reach of brute force, and substantial mathematics is needed. Or for the lazy, it is possible to find small values by brute force, then look the sequence up on OEIS to find the formula.

### Bijection to a matrix representation

We find that any instance of the problem can be represented, or bijected to a special matrix, one where each row and column is increasing.

Let us number the soldiers in the following fashion. Let the rightmost soldier, that is, the soldier first to move, be labelled 1. The soldier behind him is labelled 2, and so on, until the last soldier to move is labelled . Since the order of soldiers cannot change, each soldier moves exactly times.

Consider a very simple case, with 4 stones and 2 soldiers. One possible way is the first soldier moving twice, followed by the second moving twice.

This move sequence can be represented by . The other sequence, and the only other sequence is .

Firstly a sequence like is invalid because in a valid sequence, each soldier has to move the same number of times. Another invalid case is something like , since obviously 2 cannot move the first turn. But how can you tell whether is valid or not?

It isn’t very easy to tell in sequence form. Instead we represent the sequence as a matrix form.

Let’s try some examples first, The sequence in matrix form is:

The other sequence, , is:

Try a more complex example, :

To create the matrix, first have a counter and initialize it to 1; when the first soldier moves, place the counter in the first cell that’s unfilled in the first row, and increment the counter. Now if the second soldier moves, we place the counter in the second row (first unfilled cell), and increment it again, and so on. By the time we’re through all of the soldier moves, the matrix should be nice and rectangular.

Perhaps a different explanation is more intuitive. If (where is the matrix, means row 3, column 2), that means on move 7, soldier number 3 makes his move number 2.

From this interpretation, several important facts surface. The rows must be increasing, obviously, since if the row is not increasing, say 7 comes before 5, move 7 happened before move 5, which can’t be!

Less obviously, the column has to be increasing. Suppose that in some matrix, , and the cell directly underneath, . In that case soldier 3 made his move 7 before soldier 2 made his move 7. This results in soldier 3 *ahead *of soldier 2 (or at least on the same stone)!

So with stones and soldiers, the matrix should have rows and columns. The cells contain the numbers , while each row and each column is increasing. Our job is to enumerate these matrices, since such a matrix forms a 1-to-1 correspondence to a valid move sequence.

### Enumerating matrices with the hook length formula

A **Young tableau** is an interesting combinatorial object, based on the Ferrers diagram. From a Ferrers diagram of size , a Young tableau is one where every number from is filled in it and all rows and all columns are increasing:

From any cell of a Young tableau, a **hook **is formed by extending all the way down, and all the way to the right:

The **hook length** of a cell is the length of its hook (including itself). In the above picture, the hook length is 5. Each cell in the tableau has a hook and a hook length.

The number of valid Young tableaux with a given shape and with cells is given by the **hook length formula**:

A special case of the hook length formula can be used to enumerate rectangular Young tableaux. For instance, we have a 3*4 Young tableau. If we fill each cell with its hook length we get:

The count would then be

Or alternatively,

Simplifying:

This can be generalized to a formula. If we have rows and columns:

For , we have rows and columns, thus by substitution we arrive at our formula:

This can be used to compute , trivial to implement in Haskell or any other language.

The amount of math you know blows me away. I’m a grade 12 student in Toronto at the top of my class and you lost me at matrix. Where have you learned all this stuff?

LikeLike

Thanks. I’m not sure I know that much math (high school curriculum and some undergraduate topics) but there are plenty of resources out there for a motivated student.

LikeLike