【SICP练习】127 练习3.58

本文深入解析了由特定过程生成的数制转换流计算,通过示例(expand1710)和(expand3810),展示了如何逐步产生一系列元素,揭示了数制转换背后的算法逻辑。

练习3-58

原文

Exercise 3.58. Give an interpretation of the stream computed by the following procedure:

(define (expand num den radix) (cons-stream (quotient (* num radix) den) (expand (remainder (* num radix) den) den radix)))

(Quotient is a primitive that returns the integer quotient of two integers.) What are the successive elements produced by (expand 1 7 10) ? What is produced by (expand 3 8 10) ?

分析

(expand 1 7 10) => (quotient (* 1 10) 7) => 1 => (expand (remainder 10 7) 7 10) => (quotient (* 3 10) 7) => 4 => (expand (remainder 30 7) 7 10) => (quotient (* 2 10) 7) => 2
……
…… => 1 4 2 8 5 7 4 2 8 5 7 ...


(expand 3 8 10)
……
…… => 3 7 5 0 0 0 ...



感谢访问,希望对您有所帮助。 欢迎关注或收藏、评论或点赞。


为使本文得到斧正和提问,转载请注明出处:
http://blog.youkuaiyun.com/nomasp


版权声明:本文为 NoMasp柯于旺 原创文章,未经许可严禁转载!欢迎访问我的博客:http://blog.youkuaiyun.com/nomasp

转载于:https://my.oschina.net/nomasp/blog/503428

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值