Chinaunix首页 | 论坛 | 博客
  • 博客访问: 220881
  • 博文数量: 136
  • 博客积分: 2919
  • 博客等级: 少校
  • 技术积分: 1299
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-11 09:08
文章分类

全部博文(136)

文章存档

2013年(1)

2011年(135)

我的朋友

分类: LINUX

2011-11-18 11:11:23

  1. ;; mht created on Nov 15, 2011

  2. ;; dollar-store? : list-of-numbers -> boolean
  3. ;; to check whether all of a-list-of-nums are < 1

  4. (define (dollar-store? a-list-of-nums)
  5.   (cond
  6.     [(empty? a-list-of-nums) true]
  7.     [else
  8.      (and
  9.       (< (first a-list-of-nums) 1)
  10.       (dollar-store? (rest a-list-of-nums)))]))

  11. ;; test
  12. (dollar-store? empty)
  13. (not (dollar-store? (cons .75 (cons 1.95 (cons .25 empty)))))
  14. (dollar-store? (cons .15 (cons .05 (cons .25 empty))))

  15. ;; generalized-dollar-store? : list-of-numbers number -> boolean
  16. ;; to check whether all of a-list-of-nums are below n

  17. (define (generalized-dollar-store? a-list-of-nums n)
  18.   (cond
  19.     [(empty? a-list-of-nums) true]
  20.     [else
  21.      (and
  22.       (< (first a-list-of-nums) n)
  23.       (generalized-dollar-store? (rest a-list-of-nums) n))]))

  24. ;; test
  25. (generalized-dollar-store? empty 1)
  26. (not (generalized-dollar-store? (cons .75 (cons 1.95 (cons .25 empty))) 1))
  27. (generalized-dollar-store? (cons .15 (cons .05 (cons .25 empty))) 1)
阅读(275) | 评论(0) | 转发(0) |
0

上一篇:exam9.5.2

下一篇:exam9.5.4

给主人留下些什么吧!~~