Joel Hainley : San Francisco Bay Area Software Consultant

  • rss
  • Home
  • About
  • Reading Lists
    • 2008 Reading List
    • 2007 Reading List
    • 2006 Reading List
    • 2005 Reading List
    • 2004 Reading List
    • 2003 Reading List
    • 2002 Reading List
    • 2001 Reading List
    • 2000 Reading List
    • 1999 Reading List
    • 1998 Reading List
  • Software
    • mcalc - a tournament poker utility

Proof of my lack of brilliance

October 27, 2006

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.

Comments
2 Comments »
Categories
programming, scheme
Comments rss Comments rss
Trackback Trackback

Navigation

  • Amateur Radio
  • bicycle
  • books/reading
  • business
  • cackl
  • coding
  • flex
  • friends
  • hamtesting.com
  • knuth
  • lectures
  • life
  • observations
  • people watching
  • personal finance
  • philosophy
  • php
  • picprep
  • programming
  • reading
  • santa barbara
  • scheme
  • school
  • seo
  • uISV
  • website

Search

Archives

  • August 2008
  • July 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • November 2007
  • October 2007
  • September 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • January 2007
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006

Site Pages

  • About
  • Reading Lists
    • 1998 Reading List
    • 1999 Reading List
    • 2000 Reading List
    • 2001 Reading List
    • 2002 Reading List
    • 2003 Reading List
    • 2004 Reading List
    • 2005 Reading List
    • 2006 Reading List
    • 2007 Reading List
    • 2008 Reading List
  • Software
    • mcalc - a tournament poker utility
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox