Skip to content

Instantly share code, notes, and snippets.

@JonTanS
Created November 25, 2013 18:55
Show Gist options
  • Save JonTanS/7646648 to your computer and use it in GitHub Desktop.
Save JonTanS/7646648 to your computer and use it in GitHub Desktop.
Practice 2
;list -> number
;takes in a list of numbers and returns the mean.
(define (damean litt)
(/ (halp litt) (lengtha litt)))
(define (halp litt)
(cond [(empty? litt) 0]
[else (+ (first litt) (halp (rest litt)))]))
(define (lengtha litt)
(cond [(empty? litt) 0]
[else (+ 1 (lengtha (rest litt)))]))
(check-expect (damean (list 1 2 3 4 5)) 3)
(check-expect (damean (list 1 1 1 1 1)) 1)
(check-expect (damean (list 0 1 2 3 4)) 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment