Values arrive one at a time (star reviews on an app, sensor readings, rewards, losses) and you can’t keep them all. Write update(average, count, new_value): the new average after one more value arrives, from the old average and count, how many values that average was over. At the start nothing has arrived: average and count are both 0.
A food app shows each place’s rating. It doesn’t keep the reviews: each one is counted into the rating and thrown away, so a card only remembers two numbers, the rating and how many reviews it has. Then a 1★ review arrives at a busy restaurant and at a brand-new one.
update(average, count, new_value)| average | the average so far, over `count` values (both 0 at the start) | e.g. 0 |
| count | how many values that average was over (0 at the start) | e.g. 0 |
| new_value | the value that just arrived | e.g. 4 |
| returns | the new average, without keeping the old values | |