SICP Exercise 3.38

SICP Exercise 3.38

a) I list all the orders of the three process, and then determine the value of balance. For simplicity, I use 1, 2, 3 , instead of Peter, Paul, Mary.

123
$45
132
$35
213
$45
231
$50
312
$40
321
$40

b) If the system allows the processes to be interleaved, there are some other values that could be produced, eg. $30, $55, $60, $80, $90, $110. Here I want to show you how to get these values systematicly, I won't draw the digrams.(please refer to http://wqzhang.wordpress.com/2009/07/30/sicp-exercise-3-38/ for digrams).

We need pay attention to the time of access balance and the time of set balance. I will use the following shortcut notations:

  • a1:  access balance time of Peter.
  • a2:  access balance time of Paul.
  • a3: access balance time of Mary.
  • s1: set balance time of Peter.
  • s2: set balance time of Paul.
  • s3: set balance time of Mary.

Note: the following precedure assume that, there has interleaved parts between the three processess.

(cond ((< (max a1 a2 a3) (min s1 s2 s3))
       (cond ((= (max s1 s2 s3) s1) '$110)
             ((= (max s1 s2 s3) s2) '$80)
             ((= (max s1 s2 s3) s3) '$50)))
      ;;If s1 is big than some access time.
      ((and (> a2 s1) (> a3 s1))
       (cond ((> s2 s3) '$90)
             ((> s3 s2) '$55)))
      ((and (> a2 s1) (< a3 s1))
       (cond ((> s2 s3) '$90)
             ((> s3 s2) '$50)))
      ((and (< a2 s1) (> a2 s1))
       (cond ((> s2 s3) '$80)
             ((> s3 s2) '$55)))
      ;;If s2 is big than some access time.
      ((and (> a1 s2) (> a3 s2))
       (cond ((> s1 s3) '$90)
             ((> s3 s1) '$40)))
      ((and (> a1 s2) (< a3 s2))
       (cond ((> s1 s3) '$90)
             ((> s3 s1) '$50)))
      ((and (< a1 s2) (> a3 s2))
       (cond ((> s1 s3) '$110)
             ((> s3 s1) '$40)))
      ;;If s3 is big than some access time.
       ((and (> a1 s3) (> a2 s3))
       (cond ((> s1 s2) '$60)
             ((> s2 s1) '$30)))
      ((and (> a1 s3) (< a2 s3))
       (cond ((> s1 s2) '$60)
             ((> s2 s1) '$80)))
      ((and (< a1 s3) (> a2 s3))
       (cond ((> s1 s2) '$110)
             ((> s2 s1) '$30))))


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值