AL Alvin Li
All projects

NYT Connections web and CLI solver

Where
Personal project
When
December 2025

Project repository

Web example puzzle
Web example puzzle
Correct! It solved it!
Correct! It solved it!

How it works

  • It generates all 1,820 possible 4-word groups from a 16-word board and scores them using a combination of semantic embeddings and rule-based heuristics.
  • Uses pretrained SentenceTransformer embeddings to represent each word as a normalized vector, then scores each 4-word group by computing pairwise cosine similarities, and then calculates the average of the group.
  • Built a multi-stage pruning pipeline (top # of solutions selection + per-word frequency caps) that reduced the effective search space by 90%+ while preserving valid solutions, dramatically decreasing solve times.
  • Used a recursive backtracking algorithm that finds the combination with the highest total score with 4 disjoint groups.
  • Implemented an explain mode that breaks down each group’s score into average similarity, weakest pair similarity, and individual heuristic contributions.
  • Coded heuristic features for common puzzle patterns (plural consistency, word-length consistency, anagrams, prefixes/suffixes) to compensate for limitations of pure semantic similarity.
  • Refactored the solver core so both the CLI and web interface share the same pipeline, eliminating discrepancies caused by inconsistent normalization and thresholds.
  • Built a FastAPI backend with a clean /solve endpoint and JSON output.
  • Implemented a browser-based frontend (HTML/JS) with robust input handling (multi-word phrases, whitespace normalization, validation) and readable error states.
CLI interface example (same puzzle)
CLI interface example (same puzzle)

Lessons learned

  • Learned that raw embedding similarity is insufficient for combinatorial word puzzles and must be augmented with domain-specific heuristics.
  • Gained experience debugging algorithmic correctness vs UI integration bugs, especially when exposing the same logic through multiple interfaces.
  • Practiced designing systems that fail gracefully, providing confidence indicators and explanations instead of silent errors.