Skip to content

Instantly share code, notes, and snippets.

View Edmundworks's full-sized avatar

Edmund Cuthbert Edmundworks

View GitHub Profile
@Edmundworks
Edmundworks / SICP1.9
Created April 15, 2018 15:51
SICP 1.9
(define (+ 4 5)
(if (= 4 0)
5
(inc (+ (dec 4) 5))))
inc (+ 3 5)
inc 8
9
(if (= 4 0)
5
(+ (dec 4) (inc 5))))
(+ 3 6)
9
A
(+ 4 5)
((if (= 4 0) 5 (inc (+ (dec 4) 5))))
(inc (+ (dec 4) 5))
(inc (+ 3 5))
(inc (inc (+ 2 5)
(inc (inc (inc (+ 1 5)
(inc (inc (inc (inc (+ 0 5)
(inc (inc (inc (inc 5))))
(define (+ a b)
(if (= a 0)
b
(inc (+ (dec a) b))))
(+ 4 5)
(inc (+ (dec 4) 5))
(inc (+ 3 5))
(inc (inc (+ 2 5)))
(inc (inc (inc (+ 1 5))))
(A 1 10)
(A (- 1 1)
A 1 (- 10 1)))
A 0 (A 1 9)
(* 2 (A 1 9))
(A 1 9)
(A x y)
(A 2 4)
(A (- 2 1)
(A 2 (- 4 1))
(A 1
(A 2 3)
(A 1
(A x y)
(A 3 3)
(A (- 3 1)
(A 3 (- 3 1))
(A 2
(A 3 2))
(A 2
(A 2 2)
(A (- 2 1)
(A 2 (- 2 1)))
(A 1 (A 2 1))
(A 1 2)
@Edmundworks
Edmundworks / 1.11 - recursive
Created May 29, 2018 14:06
SICP 1.11 A function f is defined by the rule that f(n)=n if n<3 and f(n)=f(n−1)+2f(n−2)+3f(n−3) if n>3. Write a procedure that computes f by means of a recursive process.
(define (f n)
(cond ((< n 3) n)
else (+
(f (- n 1)
(* 2 (f (- n 2)))
(* 3 (f (- n 3)))))))
@Edmundworks
Edmundworks / 1.11 - iterative
Created May 29, 2018 15:25
sicp 1.1 iterative
(define (f n)
(f-iter 0 1 2 n)
define (f-iter a b c count)
(cond (= count 0) a)
(= count 1) b)
(= count 2) c)
else f-iter b c (+c (* 2 b) (* 3 a) (- count 1)