Prolog Solver Finds 14 Billion Valid Rail Cube Layouts and a 47-Point Track

Rail Cube in Prolog

Inspired by Owen Lacey's Rail Cube optimization, I built a Prolog solver for the toy train set whose tracks run along walls and upside down. Using backtracking with early cuts, it found a 47-point layout—beating the previous 42—and an exhaustive count of 14,137,062,002 distinct circuits. The solver runs under Scryer Prolog and Trealla without a constraint library, and the full enumeration was verified by a second independent run.

The Prolog search prints improvements and distinct ties, and saves them in rail-cube2-solutions.pl.

More from this day

2026-11-30