Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- ; number 11
- (define(list-of-nums? lst)
- (cond[(empty? lst) '()]
- [(=(length lst) 1) (car lst)]
- [else(number?(car lst)) (list-of-nums? (cdr lst))]))
- (define (sorted? lst)
- (cond[(empty? lst) '()]
- [(=(length lst) 1) (car lst)]
- [else(>(car lst) (second lst)) (sorted? (cdr lst))]))
- (define/contract (sort-descending lst)
- (->(and/c list? list-of-nums?) (and/c sorted? list?))
- (sort lst (λ(x y) (> x y))))
- (sort-descending '(1 99 3 2 45 6 -1 5 0 2))
- ; number 14
- (define (sum-elems-divis-by-three lst)
- (define (helper acc lst)
- (cond[(empty? lst) acc]
- [(=(remainder (car lst)3)0) (helper (+ acc(car lst)) (cdr lst))]
- [else (helper acc (cdr lst))]))
- (helper 0 lst))
- (sum-elems-divis-by-three '())
- (sum-elems-divis-by-three '(1 3 6))
- (sum-elems-divis-by-three '(2 3 4 5 6 7 8 9))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement