I am reading Hal Abelson's, Jerry Sussman's and Julie Sussman's Structure and Interpretation of Computer Programs but I am doing the exercises using Clojure. Of course, I'm not the first person to try this. This is my solution to Chapter 1, Exercise 1:
(ns sicp.ch1.ex01)
10 ; => 10
(+ 5 3 4) ; => 12
(- 9 1) ; => 8
(/ 6 2) ; => 3
(+ (* 2 4) (- 4 6)) ; => 6
(def a 3)
(def b (+ a 1))
(+ a b (* a b)) ; => 19
(if (and (> b a) (< b (* a b)))
b
a) ; => 4
(cond (= a 4) 6
(= b 4) (+ 6 7 a)
:else 25) ; => 16
(+ 2 (if (> b a) b a)) ; => 6
(* (cond (> a b) a
(< a b) b
:else -1)
(+ a 1)) ; => 16
(ns sicp.ch1.ex01)
10 ; => 10
(+ 5 3 4) ; => 12
(- 9 1) ; => 8
(/ 6 2) ; => 3
(+ (* 2 4) (- 4 6)) ; => 6
(def a 3)
(def b (+ a 1))
(+ a b (* a b)) ; => 19
(if (and (> b a) (< b (* a b)))
b
a) ; => 4
(cond (= a 4) 6
(= b 4) (+ 6 7 a)
:else 25) ; => 16
(+ 2 (if (> b a) b a)) ; => 6
(* (cond (> a b) a
(< a b) b
:else -1)
(+ a 1)) ; => 16
No comments:
Post a Comment