Calculating a rolling average without keeping all the numbers around

OK, if you know anything about maths you will read this and shake your head in dismay because it's just obvious and why did I even need to think about it? But... I was quite pleased to think this through, so I thought I'd write it down in case anybody else finds it useful. So. Your job is to calculate the average of a set of numbers. This is not hard: the average value 1 is the sum of the numbers…