- ;; mht created on Nov 15, 2011
-
-
;; dollar-store? : list-of-numbers -> boolean
-
;; to check whether all of a-list-of-nums are < 1
-
-
(define (dollar-store? a-list-of-nums)
-
(cond
-
[(empty? a-list-of-nums) true]
-
[else
-
(and
-
(< (first a-list-of-nums) 1)
-
(dollar-store? (rest a-list-of-nums)))]))
-
-
;; test
-
(dollar-store? empty)
-
(not (dollar-store? (cons .75 (cons 1.95 (cons .25 empty)))))
-
(dollar-store? (cons .15 (cons .05 (cons .25 empty))))
-
-
;; generalized-dollar-store? : list-of-numbers number -> boolean
-
;; to check whether all of a-list-of-nums are below n
-
-
(define (generalized-dollar-store? a-list-of-nums n)
-
(cond
-
[(empty? a-list-of-nums) true]
-
[else
-
(and
-
(< (first a-list-of-nums) n)
-
(generalized-dollar-store? (rest a-list-of-nums) n))]))
-
-
;; test
-
(generalized-dollar-store? empty 1)
-
(not (generalized-dollar-store? (cons .75 (cons 1.95 (cons .25 empty))) 1))
- (generalized-dollar-store? (cons .15 (cons .05 (cons .25 empty))) 1)