Add pamphlet against r start.

This commit is contained in:
K. Isom 2018-01-26 03:00:54 +01:00
parent 2c9702f334
commit 97402604df
1 changed files with 35 additions and 0 deletions

35
par/prime.rkt Normal file
View File

@ -0,0 +1,35 @@
(define (prime-numbers amount from)
(if (= amount 0)
'()
(if (prime? from)
(cons from (prime-numbers (- amount 1) (+ from 1)))
(prime-numbers amount (+ from 1)))))
(define (divisors n from)
(if (> from n)
'()
(if (= (remainder n from) 0)
(cons from (divisors n (+ from 1)))
(divisors n (+ from 1)))))
(define (prime? number)
(equal? (divisors number 1) (list 1 number)))
(define (square x) (* x x))
(define (squares list-of-numbers)
(if (eq? list-of-numbers '())
'()
(cons (square (first list-of-numbers)) (squares (rest of numbers)))))
(define (map f list)
(if (eq? list '())
'()
(cons (f (first list)) (plural f (rest list)))))
(define (sum numbers)
(if (eq? numbers '())
0
(+ (first numbers) (sum (rest numbers)))))
;; (sum (map square (prime-numbers 7 1)))