Middle Earth

sicp-exercise-1.20

Exercise 1.20

With normal-order evalutation,
(gcd 206 40)

40 != 0

(gcd 40 (r 206 40))

[(r 206 40) != 0]
=> 1 time

(gcd (r 206 40)
(r 40
(r 206 40)))

[(r 40 (r 206 40)) != 0 ]
=> 2 times

(gcd (r 40
(r 206 40))
(r (r 206 40)
(r 40
(r 206 40))))

(r (r 206 40) (r 40 (r 206 40))) != 0
=> 4 times

(gcd (r (r 206 40)
(r 40
(r 206 40)))
(r (r 40
(r 206 40))
(r (r 206 40)
(r 40
(r 206 40)))))

(r (r 40 (r 206 40)) (r (r 206 40) (r 40 (r 206 40)))) == 0
=> 7 times

(r (r 206 40) (r 40 (r 206 40)))
=> 4 times


So remainder is called 18 times

With applicative-order evalutation,
(gcd 206 40)
(gcd 40 6) 1
(gcd 6 4) 1
(gcd 4 2) 1
(gcd 2 0) 1


Remainder is called 4 times

Comments