diff --git a/SICP/code06.tm b/SICP/code06.tm index 0bd694d..7bc6910 100644 --- a/SICP/code06.tm +++ b/SICP/code06.tm @@ -215,6 +215,64 @@ \; + + \<#627E\>\<#8D28\>\<#6570\>> + + <\session|scheme|default> + <\unfolded-io|Scheme] > + (define (square x) (* x x)) + <|unfolded-io> + square + + + <\unfolded-io|Scheme] > + (define (smallest-divisor n) + + \ \ (find-divisor n 2)) + <|unfolded-io> + smallest-divisor + + + <\unfolded-io|Scheme] > + (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))))) + <|unfolded-io> + find-divisor + + + <\unfolded-io|Scheme] > + (define (divides? a b) + + \ \ (= (remainder b a) 0)) + <|unfolded-io> + divides? + + + <\unfolded-io|Scheme] > + (define (prime? n) + + \ \ (= n (smallest-divisor n))) + <|unfolded-io> + prime? + + + <\unfolded-io|Scheme] > + (prime? 7) + <|unfolded-io> + #t + + + <\input|Scheme] > + \; + + + + \<#58A8\>\<#8005\>\<#767E\>\<#79D1\>\<#FF1A\>\<#5B66\>/\<#8D39\>\<#9A6C\>\<#5C0F\>\<#5B9A\>\<#7406\>.tm> <\initial> @@ -228,6 +286,7 @@ <\references> <\collection> > + > diff --git a/SICP/index.tm b/SICP/index.tm index 572c36b..9e9ce4c 100644 --- a/SICP/index.tm +++ b/SICP/index.tm @@ -26,6 +26,8 @@ \<#7B2C\>6\<#8BFE\>\<#FF1A\>\<#7B97\>\<#6CD5\>\<#7684\>\<#65F6\>\<#7A7A\>\<#590D\>\<#6742\>\<#5EA6\>\<#FF08\>\<#4E60\>\<#9898\>\<#8BFE\>\<#FF09\> + \<#7EC3\>\<#4E60\>\<#FF1A\>\<#9898\>\<#8BFE\>\<#8BFE\>\<#4EF6\>06|https://gitee.com/XmacsLabs/interactive-sicp/raw/main/exercise06.tm> + \<#4EE3\>\<#7801\>\<#FF1A\>\<#7801\>\<#6E05\>\<#5355\>06|code06.tm> \<#7B2C\>5\<#8BFE\>\<#FF1A\>\<#7B97\>\<#6CD5\>\<#7684\>\<#65F6\>\<#7A7A\>\<#590D\>\<#6742\>\<#5EA6\>