RosettaCodeData/Task/Cumulative-standard-deviation/Pluto/cumulative-standard-deviation.pluto
2026-04-30 12:34:36 -04:00

18 lines
417 B
Text

require "table2"
local fmt = require "fmt"
local function cum_std_dev(a)
for i = 1, #a do
local b = a:slice(1, i)
fmt.print("Values : %,s", b)
coroutine.yield(b:stddev())
end
end
local a = {2, 4, 4, 4, 5, 5, 7, 9}
local co = coroutine.create(cum_std_dev)
while true do
local _, sd = coroutine.resume(co, a)
if !sd then break end
fmt.print("Std Dev : %10.8f\n", sd)
end