<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-my-2yo-taught-me-constraint-solving-zbbt3a4f8" -->

---
title: How my 2yo taught me constraint solving | daily.dev
description: A playful narrative using a Brio wooden train set as a vehicle to explain constraint solving algorithms. Starting from simple recursive backtracking, the post...
canonical: https://daily.dev/posts/how-my-2yo-taught-me-constraint-solving-zbbt3a4f8
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How my 2yo taught me constraint solving | daily.dev
og:description: A playful narrative using a Brio wooden train set as a vehicle to explain constraint solving algorithms. Starting from simple recursive backtracking, the post...
og:url: https://daily.dev/posts/how-my-2yo-taught-me-constraint-solving-zbbt3a4f8
og:image: https://api.daily.dev/og/posts/zbbt3A4f8.png
og:image:alt: How my 2yo taught me constraint solving
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How my 2yo taught me constraint solving

**[Hacker News](https://daily.dev/sources/hn)** · 22 min read · 1 upvotes · 0 comments

## Summary

A playful narrative using a Brio wooden train set as a vehicle to explain constraint solving algorithms. Starting from simple recursive backtracking, the post walks through why greedy approaches fail, how constraint satisfaction problems (CSP) are formulated, and when forward checking and global constraints help or hurt. It then introduces SAT solvers and conflict-driven clause learning (CDCL) to tackle the harder question of finding the most complex possible track layout — not just verifying a given set of pieces. Key takeaways: backtracking is simple but memoryless, CSP improves search only when useful global constraints exist, and SAT solvers change the question entirely by selecting pieces rather than just verifying them.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://thecomputersciencebook.com/posts/how-my-2yo-taught-me-constraint-solving>

## Questions this post answers

### Why did adding forward checking make my constraint solver slower instead of faster?

Forward checking only abandons a branch when a connector's shortlist of legal options empties completely, but many puzzles (like fitting Brio train pieces) have dead ends that are global rather than local: almost any piece fits almost any single open connector, so shortlists stay full until the pieces run out. Forward checking therefore detects failure at the same moment plain backtracking would, adding overhead without cutting the search.

_Debugging why a smarter-looking optimization backfires is easier with concrete comparisons like this on daily.dev._

### What is conflict-driven clause learning in a SAT solver?

Conflict-driven clause learning (CDCL) is the technique where a SAT solver guesses a variable assignment, propagates the consequences through the clauses, and when it hits a contradiction, works out which earlier guesses caused it and records that combination as a new clause so no later branch repeats the same mistake. The solver then backjumps only as far as the new clause requires, keeping everything learned across restarts.

_Developers comparing SAT-based search strategies can track deeper algorithmic breakdowns like this on daily.dev._

### Why would I use a SAT solver instead of backtracking or CSP for a piece-placement puzzle?

A SAT solver can choose which pieces to use to build the most complex valid layout, whereas backtracking and CSP solvers only answer yes or no for one fixed set of pieces and cannot decide what to leave out. The trade-off is that SAT holds every candidate placement and every learned clause in memory simultaneously, making it slower and more memory-hungry, taking seconds where the other approaches take milliseconds.

_Choosing between search strategies for combinatorial problems is easier with grounded trade-off breakdowns on daily.dev._

## Similar posts on daily.dev

- [From constraint models to playable puzzle games](https://daily.dev/posts/from-constraint-models-to-playable-puzzle-games-f3qpshgb8) · Lobsters · 0 upvotes · 0 comments
- [Blessed With Constraints: Part II](https://daily.dev/posts/blessed-with-constraints-part-ii-g3x58iqd9) · Tech Lead Digest · 0 upvotes · 0 comments
- [SATisfying Solutions to Difficult Problems\!](https://daily.dev/posts/satisfying-solutions-to-difficult-problems--outwkxh5b) · Hacker News · 0 upvotes · 0 comments
- [How Production LLMs Reason Better At Inference Time](https://daily.dev/posts/how-production-llms-reason-better-at-inference-time-weygdosue) · Daily Dose of Data Science \| Avi Chawla \| Substack · 1 upvotes · 0 comments

---

Tags: [#algorithms](https://daily.dev/tags/algorithms), [#graph-theory](https://daily.dev/tags/graph-theory)

[View this post on daily.dev](https://daily.dev/posts/how-my-2yo-taught-me-constraint-solving-zbbt3a4f8)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How my 2yo taught me constraint solving","url":"https://daily.dev/posts/how-my-2yo-taught-me-constraint-solving-zbbt3a4f8","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-my-2yo-taught-me-constraint-solving-zbbt3a4f8"},"datePublished":"2026-07-21T00:05:30.686Z","dateModified":"2026-09-13T19:16:09.866Z","description":"A playful narrative using a Brio wooden train set as a vehicle to explain constraint solving algorithms. Starting from simple recursive backtracking, the post...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7746c4dc6e41ac52aedc44a70349cec0?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/7746c4dc6e41ac52aedc44a70349cec0?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Hacker News","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Hacker News","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/hn","url":"https://daily.dev/sources/hn"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-my-2yo-taught-me-constraint-solving-zbbt3a4f8","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"algorithms,graph-theory","timeRequired":"PT22M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Hacker News","item":"https://daily.dev/sources/hn"},{"@type":"ListItem","position":3,"name":"How my 2yo taught me constraint solving"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-my-2yo-taught-me-constraint-solving-zbbt3a4f8#faq","mainEntity":[{"@type":"Question","name":"Why did adding forward checking make my constraint solver slower instead of faster?","acceptedAnswer":{"@type":"Answer","text":"Forward checking only abandons a branch when a connector's shortlist of legal options empties completely, but many puzzles (like fitting Brio train pieces) have dead ends that are global rather than local: almost any piece fits almost any single open connector, so shortlists stay full until the pieces run out. Forward checking therefore detects failure at the same moment plain backtracking would, adding overhead without cutting the search. Debugging why a smarter-looking optimization backfires is easier with concrete comparisons like this on daily.dev."}},{"@type":"Question","name":"What is conflict-driven clause learning in a SAT solver?","acceptedAnswer":{"@type":"Answer","text":"Conflict-driven clause learning (CDCL) is the technique where a SAT solver guesses a variable assignment, propagates the consequences through the clauses, and when it hits a contradiction, works out which earlier guesses caused it and records that combination as a new clause so no later branch repeats the same mistake. The solver then backjumps only as far as the new clause requires, keeping everything learned across restarts. Developers comparing SAT-based search strategies can track deeper algorithmic breakdowns like this on daily.dev."}},{"@type":"Question","name":"Why would I use a SAT solver instead of backtracking or CSP for a piece-placement puzzle?","acceptedAnswer":{"@type":"Answer","text":"A SAT solver can choose which pieces to use to build the most complex valid layout, whereas backtracking and CSP solvers only answer yes or no for one fixed set of pieces and cannot decide what to leave out. The trade-off is that SAT holds every candidate placement and every learned clause in memory simultaneously, making it slower and more memory-hungry, taking seconds where the other approaches take milliseconds. Choosing between search strategies for combinatorial problems is easier with grounded trade-off breakdowns on daily.dev."}}]}
```

