How My Two-Year-Old Taught Me Constraint Solving with Brio Trains

My two year old taught me constraint solving

How My Two-Year-Old Taught Me Constraint Solving with Brio Trains

While building Brio train layouts for my toddler, I discovered a complex algorithms problem hidden in our playtime. As we experimented with curves, straights, and crossings, my son's intuitive problem-solving mirrored sophisticated constraint satisfaction techniques. I explored how backtracking, exponential search spaces, and graph theory apply to creating closed loops, realizing that even a two-year-old can demonstrate expertise in constraint solving.

My son demonstrated a hitherto undetected expertise in constraint solving.
  1. hexasquid

    Incredible. My two-year-old forgets to include Lambek when lecturing on Curry-Howard-Lambek correspondence. Kids.

  2. dmoy

    While similarly playing brio with a two year old, I thought about a different dimension not mentioned here - super loose tolerances make the search space really weird.

    In true 2-year-old fashion, my kid would bend the rules as much as possible by literally forcing pieces to the edge of their tolerance to make things fit that shouldn't fit. 8 piece circle yea, cool, but with a sufficiently old brio set handed down for 40 years or whatever, you can totally make a 7 piece "circle" thing.

    So I decided some day I'll craft an interview question out of that, to see if people can figure out a good way to map a set of pieces laid out with given tolerance ranges for piece, see if it can connect, etc. Haven't thought about it enough to really polish it for an interview, but some day.

  3. wiredfool

    Had something similar to this with the kids with Lego Duplo tracks, similar topology but the switches gave the system state. Going "backwards" through a switch set the train to return that direction when coming the other way.

    So we had a goal to make the train do interesting behaviors, like cover the entire track autonomously, pushing the switches itself. The biggest run I remember was a 4 bit counter.

    Kid is now entering his last year of CS + Maths degree, so I guess it checks out.

  4. olooney

    I wrote several polyomino solvers for this project:

    https://www.oranlooney.com/demos/soma-forest/

    One of them used constraint solving with Z3, which was indeed reasonably fast. However, by far the fastest was a simple backtracking solver written in Rust which used bit twiddling to quickly test for intersections. For polyomino's in particular, this represents between 10x and 100x constant speed boost, depending on the size of board. There's no way to get that back with a smarter solver.

  5. elcaro

    Similar article I read 10 years ago that covers some of the same ground, with some pretty SVG's as well.

    http://strangelyconsistent.org/blog/train-tracks

More from this day

2026-07-20