Advertisement
Guest User

MomoIsPrime

a guest
Oct 7th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.39 KB | None | 0 0
  1. #lang racket
  2. (define (prime? p)
  3.   (define (non-divisible-by n d)
  4.     (cond
  5.      ((= d 1) #t)
  6.      (else (if(= (remainder n d) 0)
  7.           #f
  8.           (non-divisible-by n (- d 1))))))
  9.   (if (= p 1)
  10.       #f
  11.       (non-divisible-by p (- p 1))))
  12.  
  13. (define (sumprimes a b)
  14.   (if(> a b)
  15.      0
  16.      (if(prime? a)
  17.         (+ a (sumprimes (+ a 1) b))
  18.         (sumprimes (+ a 1) b))
  19.   ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement