Skip to content

Instantly share code, notes, and snippets.

View mmonette's full-sized avatar

Mike Monette mmonette

  • Reston, VA
  • 08:45 (UTC -04:00)
View GitHub Profile
@mmonette
mmonette / SICP1.3.scm
Created March 6, 2011 02:11
Answers for SICP Ex. 1.3
;; Exercise 1.3
;; Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers
(define (square x) (* x x))
(define (sum-of-squares x y) (+ (square x) (square y)))
(define (ss-two-largest x y z)
(cond ((> x y) (sum-of-squares x (max y z)))
(else (sum-of-squares y (max x z)))))
@mmonette
mmonette / SICP1.2.scm
Created March 6, 2011 02:10
Answers for Ex. 1.2
;; Translate into prefix form:
;; (5 + 4 + (2 - (3 - (6 + 4/5)))) / (3 * (6 - 2) * (2 - 7))
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7)))
@mmonette
mmonette / SICPEx1.1.scm
Created March 5, 2011 17:28
My answers for Ch.1 Exercise 1
;; What is the response printed by the interpreter for each expressoin?
10
;; answer: 10
(+ 5 3 4)
;; answer: 12
(- 9 1)
;; answer: 8
(/ 6 2)
;; answer: 3
(+ (* 2 4) (- 4 6))