Instantly share code, notes, and snippets.

# Enigmatic Apeenigmaticape

• Sort options
Created Oct 26, 2012
View sesslist.php

Created Nov 4, 2012
Some code to go with an exploration of SICP exercise 1.13, a proof of closed form of Fibonacci function.
View sicp_ex_1.13.scm
 ;; expt is three characters too long on the REPL ;; I use on my iPhone (define (^ x n) (expt x n)) ;; Golden Ratio, phi and the conjugate, psi (define psi (/ (- 1 (sqrt 5)) 2)) (define phi (/ (+ 1 (sqrt 5)) 2)) ;; Linear recursive Fib (define (fib n)
Created Nov 4, 2012
Various python code to do Fibonacci related computations
View sicp_1_13_pyfib.py
 #!/usr/bin/python # This is the python script I used to generate # the table that illustrates my rambling answer # to SICP exercise 1.13 import math # Golden ratio and conjugate phi = (1 + math.sqrt( 5 ) ) / 2
Created Nov 4, 2012
Recursivley compute the elements of Pascal's triangle in Scheme. Answer to SICP exercise 1.12
View pascal-element.scm
 ;; Recursive function to compute the elements ;; of Pascal's triangle. Note the complete lack ;; of any sanity checks on the input. GIGO. (define (pelem row col) (cond((= col 0) 1) ((= col row) 1) (else(+(pelem(- row 1)(- col 1)) (pelem(- row 1) col) ) )))
Created Nov 4, 2012
Iterative function f(n) from SICP exercise 1.11
View sicp_ex_1.11.scm
 ; f(n) = n if n < 3, ; f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n > 3 ; ; iterative (via tail recursion optimisation) (define (F-iter a b c count) (if (= count 0) c (F-iter (+ a (* 2 b) (* 3 c)) a
Created Nov 4, 2012
Recursive Fibonacci in Scheme, a snippet from SICP
View recfib.scm
 (define (fib n) (cond ((= n 0) 0) ((= n 1) 1) (else (+ (fib (- n 1)) (fib (- n 2))))))
Created Nov 4, 2012
Iterative (tail recursive) Fibonacci in Scheme (a snippet from SICP)
View iterfib.scm
 (define (fib n) (fib-iter 1 0 n)) (define (fib-iter a b count) (if (= count 0) b (fib-iter (+ a b) a (- count 1))))
Created Nov 4, 2012
Recursive function f(n), for completeness, from SICP exercise 1.11
View recf.scm
 (define (F n) (cond ( (< n 3) n) ( else (+ (F (- n 1)) (* (F (- n 2)) 2) (* (F (- n 3)) 3)))))
Created Nov 4, 2012
Ackermann's function, as given in SICP.
View ackermann.scm
 (define (A x y) (cond ((= y 0) 0) ((= x 0) (* 2 y)) ((= y 1) 2) (else (A (- x 1) (A x (- y 1))))))
Created Nov 5, 2012
(h)n = 2^(h-1) SICP Exercise 1.10
View sicp_ex_1.10a.scm
 ;; Recursively defined analogue of (h n) = (A 2 n) (define (h-rec n) (cond ((= n 0) 0) ((= n 1) 2) (else (expt 2 (h-rec (- n 1))))))
You can’t perform that action at this time.