Created
November 25, 2013 18:53
-
-
Save yabberyabber/7646579 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;function lis-length returns the length of a list | |
;;list -> number | |
(define (lis-length lis) | |
(cond [(empty? lis) 0] | |
[else (add1 (lis-length (rest lis)))])) | |
(check-expect (lis-length (list 1 2 3 4 5)) 5) | |
(check-expect (lis-length empty) 0) | |
(check-expect (lis-length (list 1)) 1) | |
;;function mean computes the mean of a list of numbers | |
;;list-of-numbers -> number | |
(define (mean lis) | |
(cond [(empty? (rest lis)) (first lis)] | |
[else (/ (+ (* (mean (rest lis)) | |
(lis-length (rest lis))) | |
(first lis)) | |
(lis-length lis))])) | |
(check-expect (mean (list 0 2)) | |
1) | |
(check-expect (mean (list 10 10 10 10 0)) | |
8) | |
(check-expect (mean (list 8)) | |
8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment