Anonymous user
Cumulative standard deviation: Difference between revisions
→{{header|Scheme}}
(→{{header|Forth}}: Fixed to return the running standard deviation) |
|||
Line 2,906:
=={{header|Scheme}}==
<lang scheme>
(define (
(
(lambda (x)
(set! nums (cons x nums))
(let* ((mean (/ (apply + nums) (length nums)))
(mean-sqr (lambda (y) (expt (- y mean) 2)))
(variance (/ (apply + (map mean-sqr nums)) (length nums))))
(sqrt variance)))))
(let loop ((f (standart-deviation-generator))
(input '(2 4 4 4 5 5 7 9)))
(if (not (null? input))
(begin
(display (f (car input)))
(newline)
(loop f (cdr input)))))
</lang>
|