#!/usr/bin/ruby

class sma_generator(period, list=[], sum=0) {

    method SMA(number) {
        list.append(number)
        sum += number
        list.len > period && (
            sum -= list.shift;
        )
        return (sum / list.len)
    }
}

var ma3 = sma_generator(3)
var ma5 = sma_generator(5)

for num in (1..^6, 6^..1) {
  printf("Next number = %d, SMA_3 = %.3f, SMA_5 = %.1f\n",
    num, ma3.SMA(num), ma5.SMA(num))
}
