an implementation of integer moving average algorithm