博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【SICP练习】135 练习3.66
阅读量:7236 次
发布时间:2019-06-29

本文共 2557 字,大约阅读时间需要 8 分钟。

练习3-66

原文

Exercise 3.66. Examine the stream (pairs integers integers). Can you make any general comments about the order in which the pairs are placed into the stream? For example, about how many pairs precede the pair (1,100)? the pair (99,100)? the pair (100,100)? (If you can make precise mathematical statements here, all the better. But feel free to give more qualitative answers if you find yourself getting bogged down.)

分析

对于序对(m,n)有两种情况:

1) m = n
(m,n)=2^m-2
2) m < n
(m,n)=2^m*(n-1) + 2^(m-1)-2

(1,100)=2^1*99+2^0-2=198-1=197

代码

(define (stream-take-while pred? stream)    (if (stream-null? stream)        '()        (if (pred? (stream-car stream))            (cons-stream (stream-car stream)                         (stream-take-while pred? (stream-cdr stream)))            '())))(define before-1-100 (stream->list             (stream-take-while                    (lambda (pair)                            (not (equal? pair '(1 100))))                   (pairs integers integers))));Value: before-1-100before-1-100;Value 13: ((1 1) (1 2) (2 2) (1 3) (2 3) (1 4) (3 3) (1 5) (2 4) (1 6) (3 4) (1 7) (2 5) (1 8) (4 4) (1 9) (2 6) (1 10) (3 5) (1 11) (2 7) (1 12) (4 5) (1 13) (2 8) (1 14) (3 6) (1 15) (2 9) (1 16) (5 5) (1 17) (2 10) (1 18) (3 7) (1 19) (2 11) (1 20) (4 6) (1 21) (2 12) (1 22) (3 8) (1 23) (2 13) (1 24) (5 6) (1 25) (2 14) (1 26) (3 9) (1 27) (2 15) (1 28) (4 7) (1 29) (2 16) (1 30) (3 10) (1 31) (2 17) (1 32) (6 6) (1 33) (2 18) (1 34) (3 11) (1 35) (2 19) (1 36) (4 8) (1 37) (2 20) (1 38) (3 12) (1 39) (2 21) (1 40) (5 7) (1 41) (2 22) (1 42) (3 13) (1 43) (2 23) (1 44) (4 9) (1 45) (2 24) (1 46) (3 14) (1 47) (2 25) (1 48) (6 7) (1 49) (2 26) (1 50) (3 15) (1 51) (2 27) (1 52) (4 10) (1 53) (2 28) (1 54) (3 16) (1 55) (2 29) (1 56) (5 8) (1 57) (2 30) (1 58) (3 17) (1 59) (2 31) (1 60) (4 11) (1 61) (2 32) (1 62) (3 18) (1 63) (2 33) (1 64) (7 7) (1 65) (2 34) (1 66) (3 19) (1 67) (2 35) (1 68) (4 12) (1 69) (2 36) (1 70) (3 20) (1 71) (2 37) (1 72) (5 9) (1 73) (2 38) (1 74) (3 21) (1 75) (2 39) (1 76) (4 13) (1 77) (2 40) (1 78) (3 22) (1 79) (2 41) (1 80) (6 8) (1 81) (2 42) (1 82) (3 23) (1 83) (2 43) (1 84) (4 14) (1 85) (2 44) (1 86) (3 24) (1 87) (2 45) (1 88) (5 10) (1 89) (2 46) (1 90) (3 25) (1 91) (2 47) (1 92) (4 15) (1 93) (2 48) (1 94) (3 26) (1 95) (2 49) (1 96) (7 8) (1 97) (2 50) (1 98) (3 27) (1 99) (2 51))(length before-1-100);Value: 197

(注:代码来源于网络)



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


为使本文得到斧正和提问,转载请注明出处:


版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

转载于:https://www.cnblogs.com/NoMasp/p/4786065.html

你可能感兴趣的文章
ios_随手篇1_关于捕捉scrollView的滑动方向
查看>>
流水账 - 初始化hadoop服务所要使用到的命令
查看>>
Spring Cloud Edgware新特性全接触
查看>>
人生面临众多选择,在分岔路口能否做好每一道选择题呢?
查看>>
从零开始写简易读写分离,不难嘛!
查看>>
CoreOS实践指南(十):在CoreOS上的应用服务实践(下)
查看>>
CentOS 配置第三方epo源
查看>>
老李分享:持续集成学好jenkins 2
查看>>
笔试三 15
查看>>
php 面向对象之解析
查看>>
linux 添加用户
查看>>
【安全牛学习笔记】常用工具-NETCAT
查看>>
使用精简版jdk9在docker上运行springboot2
查看>>
MySQL 5.7.18 Source Code Installation
查看>>
Java中的可变参数
查看>>
JSP中的contextPath的获取与设置
查看>>
Java代理(静态/动态 JDK,cglib)
查看>>
shell编程进阶
查看>>
12.15-Linux目录结构
查看>>
运维自动化、虚拟化
查看>>