00-part.scm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (use-modules (ice-9 nice-9)
  2. (srfi srfi-1)
  3. (pamphlet))
  4. #;(define (sum numbers)
  5. (if (eq? numbers ’())
  6. 0
  7. (+ (car numbers) (sum (cdr numbers)))))
  8. #;(define (map f l)
  9. (if (eq? l ’())
  10. ’()
  11. (cons (f (car l)) (map f (cdr l)))))
  12. (define (square number)
  13. (* number number))
  14. (define (squares numbers)
  15. (if (eq? numbers '())
  16. '()
  17. (cons (square (car numbers)) (squares (cdr numbers)))))
  18. (define ((divides? a) b)
  19. (= (remainder a b) 0))
  20. (define (divisors n from)
  21. (if (> from n)
  22. '()
  23. (if (= (remainder n from) 0)
  24. (cons from (divisors n (+ from 1)))
  25. (divisors n (+ from 1)))))
  26. (define (prime? number)
  27. (equal? (divisors number 1) (list 1 number)))
  28. (define (prime-numbers amount from)
  29. (if (= amount 0)
  30. '()
  31. (if (prime? from)
  32. (cons from (prime-numbers (- amount 1) (+ from 1)))
  33. (prime-numbers amount (+ from 1)))))
  34. ;; Wow! This is a neat little trick to annotate what an argument
  35. ;; actually stands for, when it is not a keyword argument!
  36. (apply + (map square (prime-numbers 7 #;greater-than-or-equal 1)))