C# linear iterative smoothing algorithm