原版题目:

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平方。

最新文章

  1. C#异步编程(一)
  2. BZOJ2809: [Apio2012]dispatching
  3. JS新API标准 地理定位(navigator.geolocation)/////////zzzzzzzzzzz
  4. html5移动端Meta设置
  5. 12、C#基础整理(结构体)
  6. hdu 5025 Saving Tang Monk 状态压缩dp+广搜
  7. linux内核--内存管理(二)
  8. Google API v3 设置Icon问题处理
  9. (C#)Windows Shell 编程系列1 - 基础,浏览一个文件夹
  10. gcc-config: Active gcc profile is invalid解决办法
  11. 小师妹问 easyUI mergeCells 行合并后表头和内容对不齐
  12. bzoj1444[Jsoi2009]有趣的游戏[AC自动机]
  13. node.js学习5--------------------- 返回html内容给浏览器
  14. 搭建opencv javaweb项目
  15. Python从入门到超神之文件处理
  16. java使用正则表达式
  17. IOS 小新兵
  18. vsCode_1.27.2
  19. 洛谷P1286 两数之和
  20. Tomact8部署在linux下启动很慢详解

热门文章

  1. PHP array_udiff() 函数
  2. PHP strspn() 函数
  3. Python Cookbook(第3版) 中文版 pdf完整版|网盘下载内附提取码
  4. springboot集成mongo
  5. MySQL的undo/redo日志和binlog日志,以及2PC
  6. com.fasterxml.jackson.core.JsonParseException: Unrecognized token &#39;user&#39;
  7. 网络安全传输系统-sprint1传输子系统
  8. 经典的IPC问题
  9. Vue 函数式组件 functional
  10. s2-001漏洞复现