I decided to come up with a puzzle for my friends at lunch today, and it seems to be much more complicated then I would have ever imagined. Here's the puzzle:
A rook is located at the top left corner of a $4\times4$ chessboard, as shown (image 1).
At any given point, the rook only has two legal moves:
- Move down 1 square
- Move right 1 square
The rook cannot move diagonally. The rook cannot move up or left.
Here's the puzzle: how many distinct paths can the rook take to get to the bottom right corner (Point A)?
I quickly realized that counting all the paths would work, but it would be a pain to keep track of all of them. So I spent a lot of time confused, but after a while, I found a pretty elegant solution (image 2).
All of the paths (that the rook can take) must pass through exactly one of the following points: $B, C, D$, or $E$ (see image). And so tracking all of the paths gets much easier – you just have to add up the valid paths that pass through each letter.
Only 1 path can pass through B – since the rook has to hug the wall to get to Point B. And by symmetry, only 1 path can pass through E. Point C gets a bit trickier. From the rook's starting position, the rook has 3 ways to get to C – and from C, the rook has $3$ ways to get to $A$. So we multiply $3\times 3$, so we have 9 paths through C. And by symmetry, we also have 9 paths through D.
So in total, for a 4x4 board, we have 20 valid paths from the top left corner to A.
Now, there's also the case of the $2\times2$ and $3\times3$ chessboards, with the same setup (rook in top left, A in bottom right). Finding the valid paths for a 2x2 board is trivial – there are only 2 valid paths. And you can pretty easily count the valid paths for a 3x3 board: there are 6 valid paths. (I'm gonna disregard a $1\times1$ board, because there isn't really a "path".)
So for a square chessboard of dimensions $N\times N$, the rook has a certain number of valid paths:
| N | Valid Paths |
|---|---|
| 2 | 2 |
| 3 | 6 |
| 4 | 20 |
Now, you could just use the method I described earlier for finding the number of valid paths for a NxN board. But that's long and time-consuming, especially as N increases. So I had ChatGPT write me a bit of Python code (which it did):
def count_paths(N):
dp = [[0 for _ in range(N)] for _ in range(N)]
dp[0][0] = 1
for i in range(N):
dp[i][0] = 1
dp[0][i] = 1
for i in range(1, N):
for j in range(1, N):
dp[i][j] = dp[i-1][j] + dp[i][j-1]
return dp[N-1][N-1]
Now I'm not very good at Python, so I don't really know what ChatGPT is doing – but when I asked it to return 'count_paths(4)', it gave me the correct answer of 20. And it gave me the correct answer for 'count_paths(3)' [which is 6] and 'count_paths(2)' [which is 2] – so I guess the code works.
Also, I didn't want to manually input 'count_paths(N)' and manually put those entries into a table. So I slapped the code into a Python compiler, and added this line to the code that ChatGPT wrote:
for i in range(2, 20):
print(i, count_paths(i), round(count_paths(i)/count_paths(i - 1), 7))
So what's going on here? Well, for 2 ≤ N ≤ 19, I made the program output N, the number of valid paths for an NxN board, and the ratio of count_paths(N) / count_paths(N - 1) [rounded to 7 decimal places]. Here's the output:
| N | Valid Paths | Ratio |
|---|---|---|
| 2 | 2 | 2.0 |
| 3 | 6 | 3.0 |
| 4 | 20 | 3.3333333 |
| 5 | 70 | 3.5 |
| 6 | 252 | 3.6 |
| 7 | 924 | 3.6666667 |
| 8 | 3432 | 3.7142857 |
| 9 | 12870 | 3.75 |
| 10 | 48620 | 3.7777778 |
| 11 | 184756 | 3.8 |
| 12 | 705432 | 3.8181818 |
| 13 | 2704156 | 3.8333333 |
| 14 | 10400600 | 3.8461538 |
| 15 | 40116600 | 3.8571429 |
| 16 | 155117520 | 3.8666667 |
| 17 | 601080390 | 3.875 |
| 18 | 2333606220 | 3.8823529 |
| 19 | 9075135300 | 3.8888889 |
So as you can see, the valid paths for an NxN board gets really big, really fast. That's what happens whenever you have an exponential function like this.
But what's the pattern here?
The ratio doesn't follow any common patterns. Not the Fibonacci sequence, not a typical pattern, not an algebraic rule. Nothing. Maybe ChatGPT hallucinated and created incorrect code?
Notice that the ratio gradually increases – but it doesn't seem to increase beyond 4. And this holds true if you change 'for i in range(2, 20)' to 'for i in range(2, 100)'. The ratio seems to asymptote at 4, which is super strange.
What is going on here? Why does the ratio asymptote at 4? Why does this seemingly simple question so complicated?
Would appreciate any help. – waffles2124