Solving “Knight Moves 6” (Jane Street Puzzle, October 2024)

A Random Search for Two Knight Trips Worth 2024 Points

The Puzzle

This puzzle is straightforward. As explained on the webpage, a 6x6 chessboard has squares labeled from A to C, corresponding to positive integers. The puzzle is solved by assigning values to A, B, and C and creating two corner-to-corner trips using knight’s moves so that each trip scores 2024. The method to calculate the score is: a trip starts with A points; then (a) moving between two different integers multiplies the score by the value the knight is moving to, and (b) moving between two identical integers increments the score by the value the knight is moving to. Last constraint: a square can only be visited once per trip (but a square does not necessarily have to be visited).

The official webpage distinguishes between optimal trips and trips which, while not optimal, are qualifying (i.e., A + B + C < 50).

The Solver

To solve the puzzle, I developed a solver that generates random legal knight moves for each trip. The solver also produces combinations of ABC values that satisfy the constraint A + B + C < 50. It calculates the score corresponding to each combination of values for each path. When a score equals 2024, the solver verifies whether an opposing trip exists with the same values and score. If not, the trip is retained in memory until an opposing trip is found with the same values. However, if an opposing trip does exist, the two trips are evaluated against the global best score. If the total score is the lowest recorded, the combination of possible values is updated to ensure that their sum cannot exceed the best sum during the next exploration, thereby facilitating a rapid convergence toward the optimal solution.

Results

The best values give the minimal sum, 6 (A: 1, B: 3, C: 2): A, B and C are distinct positive integers, so their sum cannot be lower than 1 + 2 + 3. For these values, the shortest pair of trips that the solver found visits 30 squares, 15 per trip, as in this example, rendered by the solver:

A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 1, B = 3 and C = 2, sum 6. Two knight trips cross it, 30 squares in all, each scoring 2024. The solid blue trip, 15 squares, goes a1, b3, c1, e2, d4, b5, d6, e4, f2, d1, b2, c4, b6, d5, f6. The dashed rust trip, 15 squares, goes a6, c5, e4, f2, d3, e1, f3, e5, c6, d4, c2, a3, c4, e3, f1. Both trips make the move e4 to f2.A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 1, B = 3 and C = 2, sum 6. Two knight trips cross it, 30 squares in all, each scoring 2024. The solid blue trip, 15 squares, goes a1, b3, c1, e2, d4, b5, d6, e4, f2, d1, b2, c4, b6, d5, f6. The dashed rust trip, 15 squares, goes a6, c5, e4, f2, d3, e1, f3, e5, c6, d4, c2, a3, c4, e3, f1. Both trips make the move e4 to f2.

The solver has also identified several other solutions, with larger sums or longer trips, as depicted below:

ABCSumSquares of the two tripsWhat it shows
132615 + 15 = 30Minimal sum, shortest pair found (above)
312621 + 27 = 48Minimal sum with other values, longer trips
612915 + 15 = 30Same length, larger sum
2181119 + 23 = 42
2122259 + 11 = 20Short trips need a large C
32444911 + 9 = 20Just under the limit of 50

A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 3, B = 2 and C = 44, sum 49. Two knight trips cross it, 20 squares in all, each scoring 2024. The solid blue trip, 11 squares, goes a1, b3, d2, b1, a3, c2, d4, e6, f4, d5, f6. The dashed rust trip, 9 squares, goes a6, b4, c2, a3, c4, b6, d5, e3, f1. Both trips use the move between a3 and c2, in opposite directions.A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 3, B = 2 and C = 44, sum 49. Two knight trips cross it, 20 squares in all, each scoring 2024. The solid blue trip, 11 squares, goes a1, b3, d2, b1, a3, c2, d4, e6, f4, d5, f6. The dashed rust trip, 9 squares, goes a6, b4, c2, a3, c4, b6, d5, e3, f1. Both trips use the move between a3 and c2, in opposite directions.

A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 2, B = 1 and C = 22, sum 25. Two knight trips cross it, 20 squares in all, each scoring 2024. The solid blue trip, 9 squares, goes a1, c2, d4, e2, c3, d1, f2, e4, f6. The dashed rust trip, 11 squares, goes a6, b4, d3, c5, e4, d2, c4, d6, f5, e3, f1.A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 2, B = 1 and C = 22, sum 25. Two knight trips cross it, 20 squares in all, each scoring 2024. The solid blue trip, 9 squares, goes a1, c2, d4, e2, c3, d1, f2, e4, f6. The dashed rust trip, 11 squares, goes a6, b4, d3, c5, e4, d2, c4, d6, f5, e3, f1.

A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 2, B = 1 and C = 8, sum 11. Two knight trips cross it, 42 squares in all, each scoring 2024. The solid blue trip, 19 squares, goes a1, c2, a3, b5, c3, a4, c5, d3, b2, c4, e5, f3, d2, f1, e3, f5, d6, e4, f6. The dashed rust trip, 23 squares, goes a6, c5, d3, b2, d1, f2, e4, d2, b1, a3, c2, a1, b3, c1, a2, b4, c6, a5, c4, b6, d5, e3, f1. Both trips use the moves between a1 and c2, a3 and c2, b2 and d3, c5 and d3, e3 and f1, in either direction.A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 2, B = 1 and C = 8, sum 11. Two knight trips cross it, 42 squares in all, each scoring 2024. The solid blue trip, 19 squares, goes a1, c2, a3, b5, c3, a4, c5, d3, b2, c4, e5, f3, d2, f1, e3, f5, d6, e4, f6. The dashed rust trip, 23 squares, goes a6, c5, d3, b2, d1, f2, e4, d2, b1, a3, c2, a1, b3, c1, a2, b4, c6, a5, c4, b6, d5, e3, f1. Both trips use the moves between a1 and c2, a3 and c2, b2 and d3, c5 and d3, e3 and f1, in either direction.

A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 6, B = 1 and C = 2, sum 9. Two knight trips cross it, 30 squares in all, each scoring 2024. The solid blue trip, 15 squares, goes a1, c2, e1, d3, b2, a4, c3, b1, d2, f1, e3, c4, b6, d5, f6. The dashed rust trip, 15 squares, goes a6, b4, d5, b6, c4, a5, b3, c5, a4, c3, e2, d4, f3, d2, f1. Both trips use the moves between a4 and c3, b6 and c4, b6 and d5, d2 and f1, in either direction.A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 6, B = 1 and C = 2, sum 9. Two knight trips cross it, 30 squares in all, each scoring 2024. The solid blue trip, 15 squares, goes a1, c2, e1, d3, b2, a4, c3, b1, d2, f1, e3, c4, b6, d5, f6. The dashed rust trip, 15 squares, goes a6, b4, d5, b6, c4, a5, b3, c5, a4, c3, e2, d4, f3, d2, f1. Both trips use the moves between a4 and c3, b6 and c4, b6 and d5, d2 and f1, in either direction.

A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 3, B = 1 and C = 2, sum 6. Two knight trips cross it, 48 squares in all, each scoring 2024. The solid blue trip, 21 squares, goes a1, c2, d4, e6, f4, d5, b6, a4, c3, b5, a3, b1, d2, b3, c5, d3, e5, c4, d6, e4, f6. The dashed rust trip, 27 squares, goes a6, c5, e6, f4, d5, b4, c6, d4, f5, e3, d1, f2, e4, c3, a4, b2, c4, a5, b3, a1, c2, e1, d3, e5, f3, d2, f1. Both trips use the moves between a1 and c2, a4 and c3, d3 and e5, d5 and f4, e6 and f4, in either direction.A 6 by 6 board with files a to f and ranks 1 to 6, in three regions: A on the left, B in a band through the middle, C on the right, with A = 3, B = 1 and C = 2, sum 6. Two knight trips cross it, 48 squares in all, each scoring 2024. The solid blue trip, 21 squares, goes a1, c2, d4, e6, f4, d5, b6, a4, c3, b5, a3, b1, d2, b3, c5, d3, e5, c4, d6, e4, f6. The dashed rust trip, 27 squares, goes a6, c5, e6, f4, d5, b4, c6, d4, f5, e3, d1, f2, e4, c3, a4, b2, c4, a5, b3, a1, c2, e1, d3, e5, f3, d2, f1. Both trips use the moves between a1 and c2, a4 and c3, d3 and e5, d5 and f4, e6 and f4, in either direction.