Exercise 4.37

Read Exercise 4.37 ~ Solution


The answer is given in the question. Ben’s version obviously searches less combinations that the version in Exercise 4.35 for two reasons:

  1. The first require expression, (require (>= hsq ksq)), causes backtracking for some values of (i , j) that would be tested in the original version. So this combinations of i and j are limited.
  2. The second require expression, (require (integer? k)), causes backtracking for some values of k that would be tested, hence limiting the values of k.

Another consideration is the type of expressions used; Ben’s version uses sqrt which is a floating point operation and much slower than just using addition and multiplication, so presumably there would be some ranges that Ben’s code is slower for, probably for small values of high – low.

Leave a comment