[ prog / sol / mona ]

prog


Lisp beginner thread

39 2020-05-26 21:15

Hey anon, I've been working through SICP now that I've completed “The Seasoned Schemer”. I'm wondering if anyone would mind expressing their opinions on whether the following procedure for computing the number of ways some currency can be rearranged is inline with the philosophy of SICP:

(define (change a)
  (let C ((a a) (n (list 50 25 10 5 1)))
    (cond ((zero? a) 1)
          ((null? n) 0)
          ((>= a (car n))
            (+ (C (- a (car n)) n)
               (C a (cdr n))))
          (else (C a (cdr n))))))

Specifically my concern is if this procedure successfully decomposes the problem into parts where the implementation can be ignored as was described in Section 1.1.8. The book creates an enumeration to represent the denominations and then decrements an index to that enumeration, while I'm just using a list and the standard operations on lists. The primitives of Scheme can be shadowed though, so `car' is really just the generic idea of taking the next element in a sequence for example, and the implementation doesn't really matter. What are your thoughts?

I broke up my `pascal' function in a similar way to that of `sqrt' in the earlier section. I honestly don't think I would have been able to solve it without this because I didn't sufficiently consider the boundary conditions of Pascal's Triangle before writing the procedure, which made it far more complex than it should have been. I do value the method so far, and only wish to know if this solution is conforming.

132


VIP:

do not edit these