Home > programming, scheme > Proof of my lack of brilliance

Proof of my lack of brilliance

I’ve been reading through Structure And Interpretation Of Computer Programs in the evenings, and have started going through the exercises as well. I figure it’ll help bring home the finer points of the text, and it’s sorta like little puzzles to work on, plus i’m learning scheme, and since I have a well documented affection for lisp it works out well.

One of the first exercises that they recommended was given three numbers square the sums of the two greater numbers. Pretty straight-forward right? Yea..pretty much. I implemented the usual if (and (> a b) (> b c)) then A is the biggest number. Pretty easy to find the largest and smallest numbers with that approach. However, start coding up for the middle number and you end up with this mess of unreadable garbage, well not unreadable but you end up wishing there was something elegant you could like the above statements.

After a bit of thought I hit upon it it goes something like this (- (+ a b c) (+ (get-max-num(a b c)) (get-min-num(a b c))) which works out rather well because the both the max and min of three numbers are very easy found using just a couple of lines of code. This is obvious when you think about it, but when you’re coming from a bunch of >, <, and, cond statements it’s not the thing you would consider at first..i guess…well i didn’t.

I mentioned this to shad and his response was something along the lines of “duh, obviously b = (a + b + c) – (a + c) it’s algebra”. This response further reinforces the theory that i’m in over my head most of the time.

Categories: programming, scheme Tags:
  1. Egyptian Prescription
    December 16th, 2006 at 18:36 | #1

    Need an update – how are you?

  2. Egyptian Prescription
    January 10th, 2007 at 00:24 | #2

    For us “Joel watchers,” it really is time for you to update your blog.
    Possible Topics:
    1) What you did for Halloween,
    2) What you did for Christmas,
    3) What you did for New Years,
    4) A motorcycle ride to Sunny Santa Barbara.

  1. No trackbacks yet.