Sunday, November 15, 2009

SICP - Exercise 1.3

;; [[Exercise]]                                                                                                              

;; Exercise 1.3:                                                                                                             
;; Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.    

;; [[Sample Answer]]                                                                                                         

(define (square x)
  (* x x))
(define (sum-of-squares-of-high-numbers a b c)
  (cond ((and (<= a b) (<= a c)) (+ (square b) (square c)))
        ((and (<= b a) (<= b c)) (+ (square a) (square c)))
        (else (+ (square a) (square b)))))

;; [[Sample Test]]

(sum-of-squares-of-high-numbers 1 2 3) ; 13                                                                                  
(sum-of-squares-of-high-numbers 1 3 2) ; 13                                                                                  
(sum-of-squares-of-high-numbers 2 1 3) ; 13                                                                                  
(sum-of-squares-of-high-numbers 2 3 1) ; 13                                                                                  
(sum-of-squares-of-high-numbers 3 1 2) ; 13                                                                                  
(sum-of-squares-of-high-numbers 3 2 1) ; 13                                                                                  
(sum-of-squares-of-high-numbers 1 1 1) ; 2                                                                                   
(sum-of-squares-of-high-numbers 1 2 2) ; 8                                                                                   
(sum-of-squares-of-high-numbers 1 1 2) ; 5

Friday, November 13, 2009

SICP - Exercise 1.2

;; [[Exercise]]

;; Exercise 1.2:
;; Translate the following expression into prefix form.
;;
;; (5 + 4 + (2 - (3 - (6 + 4/5)))) / (3 * (6 - 2) * (2 - 7))

;; [[Sample Answer]]

(/ (+ 5 (+ 4 (- 2 (- 3 (+ 6 (/ 4 5)))))) (* 3 (- 6 2) (- 2 7))) ; -37/150

Sunday, November 8, 2009

First post

This is a first post. I'm testing the features of Blogger.

Google

this is inside of the p tag.



this is inside of the em tag.


legacy table layout

this is inside of the h2 tag


int main() {
  printf("Hello, world!");

  return 0;
}