SICP之1.3中文翻译题目错误
2024-09-07 20:33:46
原版题目:
Exercise 1.3: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
中文翻译书籍:
翻译错误,题目正确为:
请定义一个过程,它以三个数为参数,返回其中较大的两个数平方之和。
网上的参考答案为:
(define (square x) (* x x))
(define (sumsquares x y) (+ (square x) (square y)))
(define (sqsumlargest a b c)
(cond
((and (>= a c) (>= b c)) (sumsquares a b))
((and (>= b a) (>= c a)) (sumsquares b c))
((and (>= a b) (>= c b)) (sumsquares a c))))
我个人的答案是:
(define (sum-max-three x y z)
(define (bigger a b) (if (< a b)
b
a))
(define (smaller a b)
(if (= (bigger a b) b)
a
b))
(define (square x)
(* x x))
(+ (square (bigger x y)) (square (bigger (smaller x y) z) )))
思路是:两个数比较,取两个数中最大一个平方 加上 前面两个数中较小的如第三个数比较取较大的平方。
列如 1 2 3 max(1,2)-> 2 max(1,3)-> 3 2平方 + 3平方。
最新文章
- C#异步编程(一)
- BZOJ2809: [Apio2012]dispatching
- JS新API标准 地理定位(navigator.geolocation)/////////zzzzzzzzzzz
- html5移动端Meta设置
- 12、C#基础整理(结构体)
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
- linux内核--内存管理(二)
- Google API v3 设置Icon问题处理
- (C#)Windows Shell 编程系列1 - 基础,浏览一个文件夹
- gcc-config: Active gcc profile is invalid解决办法
- 小师妹问 easyUI mergeCells 行合并后表头和内容对不齐
- bzoj1444[Jsoi2009]有趣的游戏[AC自动机]
- node.js学习5--------------------- 返回html内容给浏览器
- 搭建opencv javaweb项目
- Python从入门到超神之文件处理
- java使用正则表达式
- IOS 小新兵
- vsCode_1.27.2
- 洛谷P1286 两数之和
- Tomact8部署在linux下启动很慢详解
热门文章
- PHP array_udiff() 函数
- PHP strspn() 函数
- Python Cookbook(第3版) 中文版 pdf完整版|网盘下载内附提取码
- springboot集成mongo
- MySQL的undo/redo日志和binlog日志,以及2PC
- com.fasterxml.jackson.core.JsonParseException: Unrecognized token &#39;user&#39;
- 网络安全传输系统-sprint1传输子系统
- 经典的IPC问题
- Vue 函数式组件 functional
- s2-001漏洞复现