Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created May 5, 2013 04:36
Show Gist options
  • Save liammclennan/5519722 to your computer and use it in GitHub Desktop.
Save liammclennan/5519722 to your computer and use it in GitHub Desktop.
Sicp 1.1 exercises
(define (doit a b c)
(define descending (sort (list a b c) >))
(+ (square (car descending)) (square (car (cdr descending))))
)
@dtchepak
Copy link

dtchepak commented May 6, 2013

My attempt using only material already introduced.

(define (square a) (* a a))

(define (sum-of-squares a b) (+ (square a) (square b)))

(define (smallest? x a b) (and (< x a) (< x b)))

(define (f a b c)
  (cond ((smallest? a b c) (sum-of-squares b c))
        ((smallest? b a c) (sum-of-squares a c))
        (else (sum-of-squares a b))
        ))

@jimmyp
Copy link

jimmyp commented May 8, 2013

My attempt https://gist.github.com/jimmyp/5538332

smallest? is much more elegant than my solution

liam where is car and cdr coming from in your solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment