Monday, June 20, 2011


Oh, I thought, I know the answer to this: it's just like the previous solution.  Onward!

Onward into a bramble bush.  First out the gate with the wrong answer, that's me.


For those playing along at home, this is the right [1] solution.

(define (sum-coins penny nickel dime quarter)
   ( + penny ( * 5 nickel) ( * 10 dime) ( * 25 quarter)))

When I learned how to write code we were expected to flowchart, then write the code down on graph paper, then enter it into the terminal. I can see the wisdom of that approach.  On the other hand, it's easy to write fast, make mistakes, then move on.  On the gripping hand it's easy to jam along and and not learn anything.

[1] For some values of right. The user must enter the number of coins in the right order, for example, which bugs me.  Also, I can see where modularizing it would help a whole bunch with readability.

blog comments powered by Disqus