diff options
author | rsiddharth <s@ricketyspace.net> | 2017-07-15 22:19:51 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2017-07-15 22:19:51 +0000 |
commit | 30535ec1f959d828241b0f9863709587094ddeec (patch) | |
tree | 0b74f258f659966395675e0d490f47b1938f3d00 /net/ricketyspace | |
parent | ab2ecb49ace565beb3f1393a59da7b7e3b399828 (diff) |
net: Add (net ricketyspace sicp one twentythree).
* net/ricketyspace/sicp/one/twentythree.scm
(net ricketyspace sicp one twentythree): Add module.
Diffstat (limited to 'net/ricketyspace')
-rw-r--r-- | net/ricketyspace/sicp/one/twentythree.scm | 25 |
1 files changed, 25 insertions, 0 deletions
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 +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. + +(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)) |