Building a Hamiltonian Path Puzzle

· web · Source ↗

TLDR

  • Number Trail is a no-framework, no-bundler browser puzzle built on Hamiltonian path theory, with Warnsdorff’s heuristic powering random puzzle generation.

Key Takeaways

  • Plain HTML/CSS/single JS module, no build step; puzzle files are plain text with three sections: metadata, grid, and walls – diffable in version control.
  • The core constraint is NP-complete (Hamiltonian path), made tractable by numbered waypoints that fix the sequence and dramatically shrink the search space.
  • Walls are placed only on edges outside the known solution path, so solvability is guaranteed by construction, not runtime decision.
  • Warnsdorff’s rule (visit the neighbor with fewest onward moves) generates valid paths on 5x5 to 10x10 grids, with snake-traversal fallback when it dead-ends.
  • Path rendering uses CSS grid gap as implicit grid lines and four directional arm elements per cell with data-attribute toggles – no layout reflow on state changes.

Hacker News Comment Review

  • No substantive HN discussion yet.

Original | Discuss on HN