From 30535ec1f959d828241b0f9863709587094ddeec Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 15 Jul 2017 22:19:51 +0000 Subject: net: Add (net ricketyspace sicp one twentythree). * net/ricketyspace/sicp/one/twentythree.scm (net ricketyspace sicp one twentythree): Add module. --- net/ricketyspace/sicp/one/twentythree.scm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 net/ricketyspace/sicp/one/twentythree.scm diff --git a/net/ricketyspace/sicp/one/twentythree.scm b/net/ricketyspace/sicp/one/twentythree.scm new file mode 100644 index 0000000..f88b05d --- /dev/null +++ b/net/ricketyspace/sicp/one/twentythree.scm @@ -0,0 +1,25 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; . + +(define-module (net ricketyspace sicp one twentythree) + #:use-module (net ricketyspace sicp utils) + #:export (smallest-divisor)) + +(define (square x) + (expt x 2)) + +(define (divides? a b) + (= (remainder b a) 0)) + +(define (next n) + (cond ((= n 2) 3) + (else (+ n 2)))) + +(define (find-divisor n test-divisor) + (cond ((> (square test-divisor) n) n) + ((divides? test-divisor n) test-divisor) + (else (find-divisor n (next test-divisor))))) + +(define (smallest-divisor n) + (find-divisor n 2)) -- cgit v1.2.3