博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SICP 练习 1.3
阅读量:2509 次
发布时间:2019-05-11

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

CL-USER> (defun sum-of-two(a b c)
       (cond ((if (>= a b c) ( + a b)))
         ((if (>= a c b) ( + a c)))
         ((if (>= b c a) ( + b c)))
         ((if (>= b a c) ( + b a)))
         ((if (>= c a b) ( + c a)))
         ((if (>= c b a) ( + c b)))))
SUM-OF-TWO
CL-USER> (sum-of-two 3 2 5)
8
CL-USER> (sum-of-two 1 2 3)
5
CL-USER> (sum-of-two 5 4 3 )
9
CL-USER> (sum-of-two 3 5 4)
9
CL-USER> (if ( < a b) a b)
4
CL-USER> (if ( < a b) a b)
3
优化一下 :
CL-USER> (DEFUN SUM-OF-TWO-1(A B C)
       (cond ((if (and (> a c) (> b c))(+ a b)))
         ((if (and (> b a) (> c a))(+ b c)))
         ( (+ a c))))
SUM-OF-TWO-1
CL-USER> (sum-of-two-1 3 2 5)
8
CL-USER> (sum-of-two-1 1 2 3)
5
CL-USER> (sum-of-two-1 5 4 3)
9
CL-USER> (sum-of-two-1 3 5 4)
9

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/133735/viewspace-749603/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/133735/viewspace-749603/

你可能感兴趣的文章
Bootstrap 基础讲解2
查看>>
获取ServletContext
查看>>
七周成为数据分析师07_统计学基础
查看>>
变革之心
查看>>
IAP Store Kit Guide(中文)
查看>>
VS 2012 ASPX 页面编辑器的一点改进
查看>>
Python单元测试框架——unittest
查看>>
django序列化 serializers
查看>>
Centos7忘记root密码,修改root密码及其他用户密码
查看>>
删除数组指定的某个元素
查看>>
centos6.3 安装配置redis
查看>>
实现Callable接口。带返回值的线程
查看>>
一行代码将两个列表拼接出第三个列表(两个可迭代对象相加产生第三个可迭代对象)--map()方法...
查看>>
程序人口--MainFrame.java
查看>>
12-25造数据库面向对象
查看>>
web开发常见问题
查看>>
C++中namespace的使用
查看>>
非常好的Oracle教程【转】
查看>>
Java基础——安装及配置
查看>>
2017-03-05 CentOS中结合Nginx部署dotnet core Web应用程序
查看>>