Best afterFiltering a list·A comparison is a yes/no value
Collecting rainwater
Read a list of heights as a skyline of columns. After rain, water pools in the dips between taller columns. The trick: each column holds water only up to the LOWER of the tallest walls on its two sides — not the tallest wall anywhere.
Heights are columns. How many cells of water are trapped between them after rain?
Click a line, drag the slider, or use the ← → keys.
What you are looking at
Toggle to the abstraction and watch the blue water fill each column: the grey bars are the heights, and total counts the trapped cells.
- Buggy — fills every column up to the global
peak. That overflows the edges — water would simply spill off the ends — and overcounts the total (11 instead of 7). - Procedural — fills each column to
min(left, right)— the lower of the tallest walls on its two sides — so the edges stay dry and the total is the correct 7.
This is a milestone — it puts several earlier ideas together into one small program.
Every state you see came from running the program under CPython's tracer at build time — see how GlassBox stays honest.