logoalt Hacker News

My two year old taught me constraint solving

70 pointsby bambataa07/10/202626 commentsview on HN

Comments

wiredfooltoday at 7:31 AM

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.

hexasquidtoday at 4:22 AM

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

dmoyyesterday at 11:07 PM

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.

show 1 reply
olooneytoday at 12:42 AM

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.

RataNovatoday at 7:02 AM

The strongest insight here is that the SAT solver did not merely solve the same problem faster. It solved a better-formulated problem: choose the pieces as well as their placement.

elcarotoday at 2:17 AM

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

poliviertoday at 12:37 AM

> When this solver backjumps, it forgets the failure as soon as it lands, so if the same dead end comes up in a different part of the search it gets rediscovered from scratch.

Modern solvers such as CP-SAT combine some SAT features with a CP solver, based of the work of Peter Stuckey I think.

comrade1234yesterday at 10:23 PM

Yon should publish this on LinkedIn.

show 1 reply
zahlmanyesterday at 11:05 PM

The kid doesn't seem to be doing any actual teaching here. Cool that a two-year-old can say "exponential", though, I guess.

> “Dada! Degree three. No Euler circuit.”

…Oh. Okay, fine, weird rhetorical device but you do you.

efavdbtoday at 1:09 AM

My three year old taught me something he saw on a YouTube video: you can search through a maze and find your way out just by keeping your right hand on the wall at all times and continuing till exit. Does a DFS.

show 3 replies
onaclov2000today at 12:36 AM

I'll be honest, while it's possible the article is genuine,at some point I felt/realized it seemed like an ad for the book, and made the story feel like it was not genuine and more like a contrived example of why the book is so useful and not real (again, not claiming real vs not real,just the vibe I felt) so I stopped reading.

show 1 reply
akoboldfryingtoday at 4:41 AM

Insidious "gift" idea: A set of wooden track pieces with lengths and join angles chosen such that no subset of them can form a closed loop. No matter what you try, it's always just a little bit off.

hyperhelloyesterday at 10:34 PM

Sometimes you have to prove you’re #1 Dad.

mcphageyesterday at 11:08 PM

What year was your son born? Nobody has said “Silly Billy” in 30 years, unless under the auspices of a duly appointed official.

show 2 replies
charcircuityesterday at 11:55 PM

This attempt at humble bragging about how smart your two year old is was not necessary for this article. There does not need to be a constant game of trying to 1 up other parents by bragging about how much farther ahead your kid is compared to others.