Skip to content

Instantly share code, notes, and snippets.

@mohanrajendran
Created July 6, 2014 23:27
Show Gist options
  • Save mohanrajendran/b4d4f5ec55d71c4e20ff to your computer and use it in GitHub Desktop.
Save mohanrajendran/b4d4f5ec55d71c4e20ff to your computer and use it in GitHub Desktop.
SICP Exercise 1.3
(define (sq x) (* x x))
; sq
(define (sumsq x y) (+ (sq x) (sq y)))
; sumsq
(define (largest2sq a b c)
(cond ((and (<= a b) (<= a c)) (sumsq b c))
((and (<= b a) (<= b c)) (sumsq a c))
(else (sumsq a b))))
; largest2sq
; Test cases:-
(largest2sq 1 2 3)
; 13
(largest2sq 1 3 2)
; 13
(largest2sq 1 1 2)
; 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment