mirror of https://gitee.com/XmacsLabs/planet.git
SICP 06: 习题课课件
This commit is contained in:
parent
fb5dd8061d
commit
81129eca29
|
@ -215,6 +215,64 @@
|
|||
\;
|
||||
</input>
|
||||
</session>
|
||||
|
||||
<section*|\<#5BFB\>\<#627E\>\<#8D28\>\<#6570\>>
|
||||
|
||||
<\session|scheme|default>
|
||||
<\unfolded-io|Scheme] >
|
||||
(define (square x) (* x x))
|
||||
<|unfolded-io>
|
||||
square
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
(define (smallest-divisor n)
|
||||
|
||||
\ \ (find-divisor n 2))
|
||||
<|unfolded-io>
|
||||
smallest-divisor
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
(define (find-divisor n test-divisor)
|
||||
|
||||
\ \ (cond ((\<gtr\> (square test-divisor) n) n)
|
||||
|
||||
\ \ \ \ \ \ \ \ ((divides? test-divisor n) test-divisor)
|
||||
|
||||
\ \ \ \ \ \ \ \ (else (find-divisor n (+ test-divisor 1)))))
|
||||
<|unfolded-io>
|
||||
find-divisor
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
(define (divides? a b)
|
||||
|
||||
\ \ (= (remainder b a) 0))
|
||||
<|unfolded-io>
|
||||
divides?
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
(define (prime? n)
|
||||
|
||||
\ \ (= n (smallest-divisor n)))
|
||||
<|unfolded-io>
|
||||
prime?
|
||||
</unfolded-io>
|
||||
|
||||
<\unfolded-io|Scheme] >
|
||||
(prime? 7)
|
||||
<|unfolded-io>
|
||||
#t
|
||||
</unfolded-io>
|
||||
|
||||
<\input|Scheme] >
|
||||
\;
|
||||
</input>
|
||||
</session>
|
||||
|
||||
\<#58A8\>\<#8005\>\<#767E\>\<#79D1\>\<#FF1A\><slink|https://gitee.com/XmacsLabs/tmmlwiki/raw/main/\<#6570\>\<#5B66\>/\<#8D39\>\<#9A6C\>\<#5C0F\>\<#5B9A\>\<#7406\>.tm>
|
||||
</body>
|
||||
|
||||
<\initial>
|
||||
|
@ -228,6 +286,7 @@
|
|||
<\references>
|
||||
<\collection>
|
||||
<associate|auto-1|<tuple|?|?>>
|
||||
<associate|auto-2|<tuple|?|?>>
|
||||
</collection>
|
||||
</references>
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
<item>\<#7B2C\>6\<#8BFE\>\<#FF1A\>\<#7B97\>\<#6CD5\>\<#7684\>\<#65F6\>\<#7A7A\>\<#590D\>\<#6742\>\<#5EA6\>\<#FF08\>\<#4E60\>\<#9898\>\<#8BFE\>\<#FF09\>
|
||||
|
||||
\<#7EC3\>\<#4E60\>\<#FF1A\><hlink|\<#4E60\>\<#9898\>\<#8BFE\>\<#8BFE\>\<#4EF6\>06|https://gitee.com/XmacsLabs/interactive-sicp/raw/main/exercise06.tm>
|
||||
|
||||
\<#4EE3\>\<#7801\>\<#FF1A\><hlink|\<#4EE3\>\<#7801\>\<#6E05\>\<#5355\>06|code06.tm>
|
||||
|
||||
<item>\<#7B2C\>5\<#8BFE\>\<#FF1A\>\<#7B97\>\<#6CD5\>\<#7684\>\<#65F6\>\<#7A7A\>\<#590D\>\<#6742\>\<#5EA6\>
|
||||
|
|
Loading…
Reference in New Issue