Skip to content

Instantly share code, notes, and snippets.

@iketiunn
Last active August 9, 2016 03:03
Show Gist options
  • Save iketiunn/879eb64c7a1dbead6cd63fb8349be60b to your computer and use it in GitHub Desktop.
Save iketiunn/879eb64c7a1dbead6cd63fb8349be60b to your computer and use it in GitHub Desktop.
SICP

Computational modle

substition modle

Linear Iteration time = O(n) space = O(1)

Linear Recursion time = O(x) space = O

Recursion

Fibonacci

(DEFINE (fib n)
  (if ( < n 2)
      n
      (+ fib(- n 1) fib(- n 2))))

time = O(log(n)), some fib was calculated (as tree nodes)

Towers of Hanoi

(define (square x)
(* x x))
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
(define (average x y)
(/ (+ x y) 2))
(define (improve guess x)
(average guess (/ x guess)))
(define (sqrt-iter guess x)
(if (good-enough? guess x)
guess
(sqrt-iter (improve guess x) x)))
(define (sqrt x)
(sqrt-iter 1.0 x))
(sqrt 9) ; 3.00009155413138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment