-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex341.lisp
68 lines (56 loc) · 3.5 KB
/
ex341.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
; Answers for 3-4-1
; Exercise 3.38
; a)
; Peter, Paul, Mary: 100 + 10 = 110
; 110 - 20 = 90
; 90 - (90/2) = 45
; Peter, Mary, Paul: 100 + 10 = 110
; 110 - (110/2) = 55
; 110 - 20 = 35
; Mary, Peter, Paul: 100 - (100/2) = 50
; 50 + 10 = 60
; 60 - 20 = 40
; b)
; There's too many different possibilities for me to bother to enumerate them all.
; e.g., if they all simultaneously access the balance:
;; Mary Bank Peter Paul
;; | +------+
;; | .---------------| $100 |----------+-------------------------.
;; | | +------+ | |
;; | | | |
;; | v v v
;; | +----------------------+ +----------------------+ +----------------------+
;; | | Access balance: $100 | | Access balance: $100 | | Access balance: $100 |
;; | +----------------------+ +----------------------+ +----------------------+
;; | | | |
;; | v v v
;; | +-----------------------+ +-----------------------+ +----------------------+
;; | | new value: 100-50=50 | | new value: 100+10=110 | | new value: 100-20=80 |
;; | +-----------------------+ +-----------------------+ +----------------------+
;; | | | |
;; | v | |
;; | +-----------------------+ | |
;; | | set! balance to 50 | | |
;; | +-----------------------+ | |
;; | | +------+ | |
;; | `------------->| $50 | | |
;; | +------+ | |
;; | v |
;; | +----------------------+ |
;; | | set! balance to 110 | |
;; | +----------------------+ |
;; | +------+ | v
;; | | $110 |<-----------' +--------------------+
;; | +------+ | set! balance to 80 |
;; | +--------------------+
;; | +------+ |
;; | | $80 |<-------------------------------------'
;; | +------+
;; |
;; |
;; |
;; v
;; time
; The set! operations could occur in any order here, so the balance could end
; up as $50, $110, or $80.
; There would be more options for if any of the accesses occurred after a set!, etc.