Problem 5: Honeycomb Walk
https://open.kattis.com/problems/honey
Given a numberbetween 1 and 14, find the number of paths of lengthon a hexagonal grid from the origin to itself.
Use a hexagonal coordinate system to keep track of the number of paths from each point to the origin:

Let's denote C[x][y][n]
as the number of paths of length n from point to the origin.
Base cases:
C[0][0][0] = 1
C[x][y][0] = 0
for all not equal tothis means that from all other coordinates on the graph, there are 0 paths of length 0 to the origin
Now consider :

For :

Notice the pattern: from any point , the number of paths to the origin of length is the sum of number of paths of length from its six neighboring points to the origin.
Recurrence relation:
C[x][y][n] = C[x-1][y-1][n-1] + C[x-1][y][n-1] + C[x][y-1][n-1] + C[x+1][y+1][n-1] + C[x+1][y][n-1] + C[x][y+1][n-1]
The solution we want is C[0][0][n]
: the number of paths of length from the origin to itself.
Note that our largest given is 14, so the farthest points from the origin are . To account for array indexing, we use a matrix of size, say, 17 x 17 x 17. Put the origin at C[8][8]
.
Last updated