Live data from Hacker News

My two year old taught me constraint solving

thecomputersciencebook.com

11–20 of 39 posts

Re: My two year old taught me constraint solving

#11
post #5

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…

I immediately got nerd-sniped by this...

A heuristic could try all kinds of fun force-directed placement stuff. For an exact solver, I think your best bet would (unfortunately) be to finely quantise the possible positions and orientations of each piece, describe each piece by 2 sets of positioned unit vectors (the vectors in one set start at the centre positions of each "hole" and are directed towards the centre of the piece, the other set is similar but holds the "plug" positions and orientations), and say that a partial solution is feasible iff every "plug" position is sufficiently far from all other plugs, and either sufficiently far from all other holes or within some small tolerances (in terms of both distance and angle) of some other hole. Actually, you would probably also need to treat the piece body as a "nothing else can occupy these positions" constraint. I say "unfortunate" because the position and orientation grids would need to be very fine relative to the size of the pieces, leading to a large state space thus long running times.

I think it would be fun to look for solutions that maximise the "badness" (e.g., sum of distances between matched holes and plugs) :)

Re: My two year old taught me constraint solving

#12
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.

Re: My two year old taught me constraint solving

#13
> 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.

Re: My two year old taught me constraint solving

#14
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.

Re: My two year old taught me constraint solving

#15

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.

> I'll be honest, while it's possible the article is genuine

No, there's not really much chance of that:

>> “Dada, real planners use SAT and its relatives for timetabling, chip layout, and routing for the same reason.”

Re: My two year old taught me constraint solving

#17
post #16

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.

This only works for two dimensional mazes where both the entrance and exit are on an edge and there are no loops in the maze.

If you introduce a bridge, or a tunnel, or put the goal in the middle, you can get stuck in a loop.

Re: My two year old taught me constraint solving

#18
post #16

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.

Throw a loop/island in the maze and see how your kid reacts.

Re: My two year old taught me constraint solving

#19
post #16

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.

I vaguely recall a windows screensaver that did this
Post reply on HN