Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell --- average of a list.

Name: Anonymous 2015-07-08 17:53

Rules:

✡ must compute arithmetic average of a list
✡ only one pass is allowed
✡ constant memory

Name: Anonymous 2015-07-14 0:36

Never used Haskell. I use Scheme though, and since TCO's required by the implementation,

(define (average lst)
(let loop ((sum 0) (len 0) (lst lst))
(if (null? lst)
(/ sum len)
(loop (+ (car lst) sum) (+ len 1) (cdr lst)))))


Similar hip functional programming shit though.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List