Clingo · Answer set programming · Runs in the browser

Clingo Garden Planner

Mark where the sun falls on your bed, pick what you want to grow, and a roughly 60-line logic program plans every square foot for spring, summer, and fall.

clingo WebAssembly constraints + optimization Plan a bed →

Why I built it

I'm a little obsessed with Clingo. You don't tell it how to solve a problem; you describe what a good answer looks like, and it finds one. A garden was the perfect excuse: every gardener already knows the rules (tomatoes want sun, beans and onions don't get along, don't plant the same family in the same spot twice), but juggling them all by hand is miserable.

What it does

The page turns your bed and crop list into facts and hands them to clingo, along with rules for sun needs, shade from tall crops, bad companions, spacing for sprawlers, and crop rotation across seasons. Then it searches for the plan with the most good neighbors and proves when it can't find a better one.

% a crop never sits in less light than it needs
:- plant(X,Y,S,C), needs(C,L), sun(X,Y,S,L2), L2 < L.

% bad companions are never neighbors, diagonals included
:- plant(X,Y,S,A), plant(X2,Y2,S,B), adj(X,Y,X2,Y2), bad(A,B).

% the same family never follows itself in a square
:- plant(X,Y,S,A), plant(X,Y,S+1,B), family(A,F), family(B,F).

Simplified for reading. Swap in the real lines from your encoding.

What was hard

Thinking in constraints instead of steps. My instinct as an engineer is to write the loop; in Clingo you write what must be true and let the solver find it. [Add the moments where it clicked, or where grounding blew up.]

What I think now

The power-to-code ratio is unreal: a few dozen lines replace what would be hundreds of lines of hand-written search. What I still don't understand well is how logic programs like this get woven into ordinary applications. That's the question I'm chasing next, and it connects straight back to the rule engines I've built for pricing.

Have a scheduling or rules problem that feels too tangled?

Get in touch