]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex4_39.rkt
solutions to 4.38, 4.39 and 4.40
[sicp.git] / src / sicp / ex4_39.rkt
1 #lang racket
2
3 #|
4
5 There are 5*5*5*5*5 possibilities. The order won't affect the results. 
6 But it will affect time. The various 'require' or 'assert' statements
7 restrict the number of options and the possibility tree.
8  
9 Let us look at the statements now.
10
11 1.    (assert (distinct? (list baker cooper fletcher miller smith)))
12 2.    (assert (not (= baker 5)))
13 3.    (assert (not (= cooper 1)))
14 4.    (assert (not (= fletcher 5)))
15 5.    (assert (not (= fletcher 1)))
16 6.    (assert (> miller cooper))
17 7.    (assert (not (= (abs (- fletcher cooper)) 1)))
18
19 If we look the constraints in isolation, 
20
21 constraint #1, will have 5*4*3*2*1 = 120 successes.
22 constraint #2 will have 5*5*5*5*4  = 2400 successes.
23
24 When they are put together, let us say #1 and then #2, then we have
25 #1 executing for 5^5 times resulting in 120 successes and so #2 executing for 120 times.
26
27 If we reverse #2 and #1, then we have #2 executing for 5^5 times giving 2400 possible 
28 values and so #1 executes for 2400 times.
29
30 So, if any condition takes more time to execute, then these numbers will be an effect, so
31 order will affect the execution times.
32
33 |#