Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs
4 votes
Accepted

SICP 1.3 Sum of Squares of two largest numbers

In my opinion this is too much code for such a simple task. Assuming that you do not have a max function, you can define it in this way: ...
Renzo's user avatar
  • 2,055
4 votes
Accepted

Pascal's triangle in mit-scheme

Keep your concerns separated One design principle that is vital to engineering good software is that of "separation of concerns". In other words, each function should be concerned with doing one, ...
Nathan Davis's user avatar
4 votes

Iterative "counting change" implementation in mit-scheme

In SICP the authors note: Count-change generates a tree-recursive process with redundancies similar to those in our first implementation of fib. (It will take quite a while for that 292 to be ...
Richard's user avatar
  • 41
3 votes
Accepted

SICP - exercise 1.7 better end test for square root approximation

sqrt-iter You compute (improve guess x) twice - this is a waste. You return guess instead ...
sds's user avatar
  • 1,405
3 votes
Accepted

SICP exercise 1.28 - miller-rabin primality test

To ensure I understood the SICP exercise correctly, I wrote my own version of the Miller-Rabin algorithm. You can look at my code and compare against yours. With this in mind, here's my correctness-...
C. K. Young's user avatar
  • 2,342
3 votes
Accepted

Church Numerals

Your function + is not correct. The definition of the sum of two Church numerals is the following: ...
Renzo's user avatar
  • 2,055
3 votes
Accepted

SICP - exercise 1.12 - pascal's triangle

You should memoise the recursive call in order to make it faster. Since each value has a computational sibling (its value is derived from (one or two) parents which also each has another child), you ...
C. K. Young's user avatar
  • 2,342
2 votes
Accepted

SICP - exercise 1.11 - tree recursion

Before looking for efficiency, note that there is a logical error in the tail recursive version of your function: it does not terminate on negative values (while the first function does terminate). ...
Renzo's user avatar
  • 2,055
2 votes

Pascal's triangle in mit-scheme

The sub-definition of pascal-item is what is being asked for in the 1.12 exercise. However it's entirely unsuited for calculating the entire triangle of X rows. ...
WorBlux's user avatar
  • 501
2 votes

Generating all unique permutations of a string

Pay attention to your substrings. Given s = "abc", then the following return empty strings. String pre = s.substring(0,0); String post = s.substring(3); Consider ...
Rick Ryker's user avatar
2 votes

Iterative "counting change" implementation in mit-scheme

If you add a running sum to the formal parameters of count-iter, you'll have a truly iterative piece of code. As-is, every time through ...
WorBlux's user avatar
  • 501
1 vote

SICP - exercise 1.7 better end test for square root approximation

With IEEE floating point numbers, the multiplication (* guess 1d-30) may underflow, leading to a 0.0 result. The test would have to be more sophisticated in a real program. Check out these links ...
smokeink's user avatar
1 vote
Accepted

SICP exercise 1.28 - miller-rabin primality test part II

Stylistically, I'd write it this way: ...
Will Ness's user avatar
  • 1,026
1 vote

Representing a queue as a procedure with local state

You did not provide implementations of the queue operations using this representation. In SICP this usually refers to syntactic sugar to make working with a data structure less awkward, e.g. ...
Gregor Ophey's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible