Values arrive one at a time (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.
| 1st | 2nd | 3rd | 4th |
|---|---|---|---|
| 2 | 4 | 9 | 1 |
| 1st | 2nd | 3rd | 4th |
|---|---|---|---|
| 2 | 3 | 5 | 4 |