AI × Math Playground · LIGHT HOPE / m566

Don't just solve the problem. Build the machine hiding inside it.

Eleven live labs. Each starts with a question a kid actually asks, teaches the real math underneath, and hands you a working AI you can poke with your own mouse. Every algorithm on this page is unit-tested — scroll to the bottom to see the proof.

Level 1 · Explorer

Estimate π by throwing darts

Throw darts blindfolded at a square with a circle inside it. Count how many land in the circle. That ratio alone — nothing else — tells you π.

π estimate
—
darts thrown
0
error
—
Blue = inside circle · coral = outside. More darts → tighter estimate.

The principle

The circle's area is π/4 of the square's. So the fraction of random darts inside the circle approaches π/4 — multiply by 4. This is the Law of Large Numbers made visible.

What you built

A Monte-Carlo estimator: the same trick that prices options, renders film lighting, and powers AlphaGo's search.

The algorithm

π ≈ 4 · (darts in circle) / (total darts)

In the ecosystem

↳ Random sampling underpins NS-v2 metrics and every ML model in the stack.

Level 1 · Explorer

Cats vs Dogs, by distance alone

The shortest path between two points is a straight line. Turn that same distance into a rule: a mystery animal is whatever its nearest neighbours are.

3
nearest verdict
click the pad →
Click anywhere. Lines connect to the k nearest known animals; the vote decides.

The principle

Distance between two feature points is Pythagoras: √((x₁−x₂)² + (y₁−y₂)²). "Most alike" just means "smallest distance."

What you built

A k-Nearest-Neighbours classifier — the simplest machine-learning model that actually works, and a first step toward symptom-matching.

The algorithm

label = majority vote of the k closest points

In the ecosystem

↳ Health track (symptom similarity) · badge similarity scoring.

Level 2 · Seeker

Predict your next score with a line

Hours studied vs test score never fall on a perfect line — so which line is "best"? The one that makes the total squared miss as small as possible.

best-fit line
y = —
points
0
Click to add your own data points — the least-squares line re-solves instantly.

The principle

Least squares: minimize Σ(predicted − actual)². Calculus hands you a closed-form slope and intercept — no guessing.

What you built

Linear regression: the workhorse behind price forecasts, sports analytics, and "students like you scored…".

The algorithm

m = (nΣxy − ΣxΣy)/(nΣx² − (Σx)²) · b = (Σy − mΣx)/n

In the ecosystem

↳ Sport track prediction · retention forecasting.

Level 3 · Builder

Teach a machine to walk downhill

What if you can't solve for the best line directly? Start anywhere, feel the slope under your feet, and step downhill. Do it enough and you arrive at the bottom.

loss (MSE)
—
steps
0
learned line
y = —
Coral line = current guess · dashed = the exact least-squares answer it's chasing.

The principle

The derivative is the slope of the loss. Step opposite the gradient and the error drops. This single idea trains every neural network on Earth.

What you built

Gradient descent — the beating heart of deep learning. Swap the line for a million weights and you have GPT.

The algorithm

m ← m − η · ∂Loss/∂m · b ← b − η · ∂Loss/∂b

In the ecosystem

↳ m558 asset generation · the engine under all model training.

Level 1 · Explorer

Sort a playlist into moods

Nobody labelled these songs. Yet they clump. Drop a few "mood centers," pull each toward the songs nearest it, repeat — and the moods reveal themselves.

3
iteration
0
status
ready
◆ = mood centers (centroids). Watch them slide until nothing changes.

The principle

A cluster's center is just the average (centroid) of its members. Assign by nearest center, recompute the average, repeat until stable.

What you built

K-means — unsupervised learning that finds structure with zero labels, the way recommenders group taste.

The algorithm

assign → nearest centroid, then centroid ← mean of its points

In the ecosystem

↳ Culture track · user segmentation.

Level 2 · Seeker

Split the world with one straight line

Two kinds of things scattered on a page. Can a single straight line separate them? A machine can find that line by itself — nudging it every time it's wrong.

mistakes
—
passes
0
status
untrained
The line starts random and rotates into place as it fixes each mistake.

The principle

A line is a dot product: w·x + b. Its sign says which side you're on. If a point is misclassified, push the line toward it.

What you built

The perceptron — the 1958 ancestor of every neural network. Stack enough and you get vision itself.

The algorithm

if wrong: w ← w + η · label · x

In the ecosystem

↳ The geometry behind the layer-master badge.

Level 2 · Seeker

Lock a note so only your friend can open it

Multiply two secret primes and something magical happens: anyone can lock a message, but only the one who knows the primes can unlock it. This is the math that guards the internet.

public: n=3233, e=17 private: d=2753 = primes 61 × 53
Your message
Locked (each letter → cᵉ mod n)
—
Unlocked with the private key (cᵈ mod n)
—
Type anything. The locked numbers look like noise — but the private key turns them back.

The principle

Modular arithmetic & prime factorization. Encrypting is c = mᵉ mod n; decrypting is m = cᵈ mod n. It works because of Euler's theorem — and it's one-way because factoring n is hard.

What you built

RSA — the public-key cryptosystem behind HTTPS, signed webhooks, and every secure login.

The algorithm

lock: c = mᵉ mod n · unlock: m = cᵈ mod n

In the ecosystem

↳ LAW-4 · the HMAC signatures on every cross-project webhook.

Level 3 · Builder

Who's the most important person in the group?

Importance isn't how many follow you — it's who follows you. A vote from an important friend counts more. That circular idea has a beautiful linear-algebra answer.

top influencer
—
selected
click a node
Click one node, then another, to add a "follows" arrow. Node size = its rank.

The principle

Model "who follows whom" as a matrix; rank is its dominant eigenvector, found by iterating until it stops changing — power iteration.

What you built

PageRank — the algorithm that launched Google, and the same idea behind friend and content recommenders.

The algorithm

rank ← (1−d)/N + d · Σ rank(followers)/outdegree

In the ecosystem

↳ The ecosystem graph itself · ecosystem-probe.

Level 3 · Builder

The smartest first guess

A good guess isn't the one most likely to be right — it's the one that teaches you the most no matter the answer. "How much you learn" has an exact unit: bits.

Expected information per opening guess (higher = smarter)
Click a word to see how it splits the remaining answers.
Ranked by Shannon entropy over the answer set. The top word learns the most on average.

The principle

Shannon entropy: H = −Σ p·log₂p. A guess that shatters the answers into many small, equally-likely buckets has high entropy — you learn more.

What you built

The engine of a Wordle solver / "20 Questions" AI — and the splitting rule inside every decision tree.

The algorithm

score(guess) = entropy of the feedback-pattern distribution

In the ecosystem

↳ The logic behind credibility scoring & decision rules.

Level 4 · Connector

How a phone names the note you played

A sound is a wiggly wave — a mess. Yet a phone instantly names the pitch. The trick: any wave is a sum of pure sine waves, and you can pull them back apart.

detected pitch
—
dominant frequency
bin —
Top = the messy wave you hear. Bottom = the spectrum; the tall bar is the pitch.

The principle

Fourier decomposition: every signal is a sum of sines at different frequencies. Correlate the wave with each frequency (using trig & complex numbers) to find how much of each is present.

What you built

A spectrum analyzer — the front end of Shazam, voice assistants, and every audio AI.

The algorithm

magnitude(k) = |Σ signal(t)·e^(−2πi kt/N)|

In the ecosystem

↳ Physics × AI · music under the culture track.

Level 4 · Connector

Why one video suddenly went viral

A trend and an epidemic obey the same equations. One number decides whether it fizzles or explodes — and you can watch it flip as you drag a slider.

R₀ = β/γ
—
peak reached
—
verdict
—
Blue = not-yet-reached · coral = currently sharing · gold = already moved on.

The principle

Three coupled differential equations (Susceptible→Infected→Recovered). The threshold R₀ = β/γ: above 1 it spreads, below 1 it dies.

What you built

The SIR model — used for real epidemics, marketing virality, and rumor spread on networks.

The algorithm

dI/dt = βSI/N − γI · outbreak ⇔ R₀ = β/γ > 1

In the ecosystem

↳ NS-v2 growth metrics · the retention & virality curve.

Proof, not vibes

Every algorithm here is unit-tested.

The exact functions running in your browser were verified against known-answer cases in Node — 23 assertions across 11 labs, all green. "Usable" means correct, and correct means tested.

  • ✓ Monte-Carlo π converges to 3.14159 (±0.02)
  • ✓ kNN: near-origin → cat, far corner → dog
  • ✓ Least squares recovers y = 2x + 1 exactly
  • ✓ Gradient descent matches the closed-form fit
  • ✓ K-means separates two blobs cleanly
  • ✓ Perceptron separates all training points
  • ✓ RSA: decrypt(encrypt(m)) = m for every letter
  • ✓ PageRank: ranks sum to 1, most-linked wins
  • ✓ DFT locates a pure tone's exact frequency bin
  • ✓ Entropy: uniform-over-4 = 2.000 bits
  • ✓ SIR conserves population; R₀>1 ⇒ outbreak
  • ✓ Every lab's core is the Node-tested function