How Many Ways Can You Build A Staircase?

Riddler Classic

From Jesse Nicholas comes a puzzle that is four small steps for a human, one giant leap for humankind:

You have 10 blocks with which to build four steps against a wall. The first step is one block high, the second is two blocks high, the third is three blocks high and the fourth is four blocks high.

However, the ground ever-so-slightly slopes down toward the wall, and both the floor and the blocks are a little bit slippery. As a result, whenever you place a block at ground level, it slides toward the wall until it hits the wall or another block. And when you place a block atop another block, it will similarly slide toward the wall until it hits the wall or another block.

Suppose the four blocks in the bottom row are labeled A, the three blocks in the second row are labeled B, the two blocks in the next row are labeled C and the topmost block is labeled D. One way to build the steps would be to place the blocks in the following order, one row at a time: A-A-A-A-B-B-B-C-C-D. You could alternatively place the blocks one column at a time: A-B-C-D-A-B-C-A-B-A. But you could not place them in the order A-B-B-A-A-A-B-C-C-D because that would mean at one point you have more blocks in the second row, B, than in the bottom row, A — a physical impossibility!

How many distinct ways are there to build these four steps using the 10 blocks?

Extra credit: Suppose you have precisely enough blocks to build a staircase with $N$ stairs. How many distinct ways are there to build this staircase?

Solution

Here are the earlier step builds:

1 Step, 1 Block

The trivial build for one step is:
A

2 Steps, 3 Blocks

The last step or column is composed of blocks A and B. These blocks are appended to the first step build.

This yields:
A-A-B A-A-B A-B-A

Because of sliding, the first two are identical. The distinct builds for two steps are:
AAB ABA

3 Steps, 6 Blocks

The last step or column is composed of blocks A, B, and C. These blocks are appended to the first two steps builds.

Appending C to the build order yields:
A-A-B-C A-B-C-A A-B-A-C.

Appending B to the build order yields:
A-A-B-B-C A-A-B-B-C A-A-B-C-B A-B-C-A-B A-B-A-B-C A-B-A-C-B

Because of sliding, the first two are identical. After appending A to the build order and eliminating sliding duplicates there are 16 distinct builds for 3 steps:

4 Steps, 10 Blocks

The last step or column is composed of blocks A, B, C, and D. These blocks are appended to the first three steps builds.

Answer

Applying the steps above, there are 768 distinct builds for 4 steps. Here is a list of them:


Extra Credit


My algorithm computed the first 5 steps in less than 2 seconds, but 6 steps was testing my processing power (>12 hours, still nothing).

The pattern above seems to fit and follow A005118. Using that and A057863, I came up with the following equation for $B(N)$ to represent the number of distinct builds for $N$ steps.

$$B(N) = \frac{\left(\dfrac{N^2 + N}{2}\right)!}{\prod_{k=1}^{N}{\left(2k-1\right)!!}}$$

Rohan Lewis

2021.03.01

Code can be found here.