From: Ramakrishnan Muthukrishnan Date: Sun, 24 Apr 2011 10:25:01 +0000 (+0530) Subject: solution to 3.38 X-Git-Url: https://git.rkrishnan.org/vdrive/%5B/%5D%20/uri/running.html?a=commitdiff_plain;h=9ddee199c3c2dd6c4ac5cf9af4e16cc3d4c1cf25;p=sicp.git solution to 3.38 --- diff --git a/src/sicp/ex3_38.rkt b/src/sicp/ex3_38.rkt new file mode 100644 index 0000000..7481849 --- /dev/null +++ b/src/sicp/ex3_38.rkt @@ -0,0 +1,69 @@ +#lang racket + +#| + +Peter: (set! balance (+ balance 10)) +Paul: (set! balance (- balance 20)) +Mary: (set! balance (- balance (/ balance 2))) + +1. + +a. Peter deposits $10 +b. Paul withdraws $20 +c. Mary withdraws half of balance. + +100 + 10 - 20 = 90 -> 90/2 -> $45 + +2. + +a. Peter deposits $10 +b. Mary withdraws half of balance. +c. Paul withdraws $20 + +100 + 10 -> 55 - 20 -> $35 + +3. + +a. Paul withdraws $20 +b. Peter deposits $10 +c. Mary withdraws half of balance. + +100 - 20 + 10 -> 110 /2 -> $55 + +4. + +a. Paul withdraws $20 +b. Mary withdraws half of balance. +c. Peter deposits $10 + +100 - 20 => 80 / 2 => 40 + 10 => 50 + +5. + +a. Mary withdraws half of balance. +b. Peter deposits $10 +c. Paul withdraws $20 + +100 / 2 => 50 + 10 - 20 => 40 + +6. + +a. Mary withdraws half of balance. +b. Paul withdraws $20 +c. Peter deposits $10 + +100 / 2 => 50 - 20 + 10 => 40 + +|# + +#| + +Balance could take many values if the three transactions are allowed to +happen concurrently. + +It could be 110, 80 or 50 if one of them mutates the balance variable +at the end depending on which one manages to finish last. It could also +be that 2 of them work concurrently and the resultant value is processed +by the third transaction. + +|# \ No newline at end of file