A React + TypeScript + Vite web app that lets users solve matchstick equation puzzles — drag a single matchstick to fix a broken equation!
- React 19 + TypeScript 5.8
- Vite 6 (build / dev server)
- TailwindCSS v4 (via
@tailwindcss/viteplugin) - Motion (animations), Lucide React (icons)
- Vitest + Testing Library (tests)
| File / Directory | Purpose |
|---|---|
index.html |
Entry point, mounts React to #root |
src/main.tsx |
React root render with StrictMode |
src/App.tsx |
Top-level app with Quiz Mode / Solver Mode toggle |
src/types.ts |
TypeScript types: SegmentPattern |
src/constants.ts |
7-segment display patterns for digits 0–9, operators +/-, and = |
src/utils.ts |
Core logic: solveEquation(), generateRandomPuzzle(), evaluateExpression(), pattern matching |
src/index.css |
TailwindCSS import + custom keyframe animations for stick highlights |
src/components/ |
UI components (see below) |
| Component | Description |
|---|---|
QuizWorkspace.tsx |
Interactive drag-and-drop puzzle mode. User picks up and places matchsticks (SVG segments) to fix a broken equation. Supports click-to-place and pointer drag. Tracks solved/failed state. |
SolverWorkspace.tsx |
Input an equation, click Solve, and see all valid 1-stick-move solutions rendered with color-coded diffs (green = added, red = removed). |
EqualsSign.tsx |
Simple SVG equals sign component. |
solveEquation()— Brute-force: tries removing each active segment and placing it on every inactive segment across all characters. Validates if the resulting equation is mathematically correct. Input capped at 20 characters.generateRandomPuzzle()— Pre-generates all valid single-digitA ± B = Cequations, then creates all 1-move permutations that produce an incorrect equation (a solvable puzzle). Results are cached.- 7-segment model — Digits and operators are represented as 7-element binary arrays mapping to a classic 7-segment display layout.
src/utils.test.ts— Unit tests for the solver and utility functionssrc/components/*.test.tsx— Component tests forEqualsSign,QuizWorkspace, andSolverWorkspace
Prerequisites: Node.js
- Install dependencies:
npm install - Run the app:
npm run dev - Run tests:
npm test
