[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/b4BtoRwq    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Feb 6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(define (smallest-divisor n)
   (find-divisor n 2))

(define (find-divisor n test-divisor)
   (cond ((> (square test-divisor) n) n)
         ((divides? test-divisor n) test-divisor)
         (else (find-divisor n (+ test-divisor 1)))))

(define (divides? a b)
   (= (remainder b a) 0))

(define (square x)
   (* x x))

(define (prime? n)
   (= n (smallest-divisor n)))

(time
  (display (prime? 10000000019))
  (newline))


Output:
1
2
#t
cpu time: 40 real time: 288 gc time: 10


Create a new paste based on this one


Comments: