Best afterAdding up a list·A comparison is a yes/no value
Running maximum
Tracking the biggest value seen so far is the accumulator pattern with a twist: what do you start it at? Seed it wrong and a whole class of inputs gives the wrong answer.
Track the largest number seen so far as you walk the list.
Running maximum — seeded at zero execution-derived · CPython
5 max_so_far = nstate after line 1 runs
-5-2-8-1
step 1 / 11
Click a line, drag the slider, or use the ← → keys.
What you are looking at
Watch max_so_far as each n goes by.
- Buggy — seeds
max_so_far = 0. With every number negative, none beats 0, so it ends at 0 — but the real maximum is -1. - Procedural — seeds
max_so_far = nums[0], so a real value is always the baseline. It ends at -1, the true maximum.
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.