From 81129eca292e73c8a980291db1d96c89e9ec7127 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Fri, 22 Mar 2024 14:02:18 +0800 Subject: [PATCH] =?UTF-8?q?SICP=2006:=20=E4=B9=A0=E9=A2=98=E8=AF=BE?= =?UTF-8?q?=E8=AF=BE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SICP/code06.tm | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ SICP/index.tm | 2 ++ 2 files changed, 61 insertions(+) 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\>