SHARE
TWEET

Untitled

a guest Dec 6th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn avg [a] (/ (reduce + a) (count a)))
  2.  
  3. (defn sq [a] (* a a))
  4.  
  5. (defn variance [a]
  6.     (let [m (avg a)
  7.         sqd (fn [x] (sq (- x m)))]
  8.         (avg (map sqd a)))
  9. )
  10.  
  11. (defn lazyvar
  12.     ([n s] (lazyvar n s 0))
  13.     ([n s c] (lazy-seq (cons
  14.         (variance (take n (drop c s)))
  15.         (lazyvar n s (inc c)))))
  16. )
  17.  
  18. (take 10 (lazyvar 5 (map (fn [a] (* a a)) (range))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top