Browse files

practice 1.21

  • Loading branch information...
1 parent c0af9bf commit 8b4fd0cdb8df2471a087e7e2eb612eadc6c44965 @cuipengfei committed Oct 7, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 Practice1.21.rkt
View
14 Practice1.21.rkt
@@ -0,0 +1,14 @@
+#lang racket
+(define (smallest-divisor n)
+ (find-divisor n 2))
+
+(define (find-divisor n guess)
+ (cond ((> (* guess guess) n) n)
+ ((= (remainder n guess) 0) guess)
+ (else (find-divisor n (+ 1 guess)))))
+
+(smallest-divisor 199)
+
+(smallest-divisor 1999)
+
+(smallest-divisor 19999)

0 comments on commit 8b4fd0c

Please sign in to comment.