This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if( ($dir = session_save_path() ) == null ) { | |
$dir = sys_get_temp_dir(); | |
} | |
var_dump( $dir ); | |
if( $dir ) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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) ) ))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (fib n) | |
(cond ((= n 0) 0) | |
((= n 1) 1) | |
(else (+ (fib (- n 1)) | |
(fib (- n 2)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (F n) | |
(cond ( (< n 3) n) | |
( else (+ (F (- n 1)) | |
(* (F (- n 2)) 2) | |
(* (F (- n 3)) 3))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (A x y) | |
(cond ((= y 0) 0) | |
((= x 0) (* 2 y)) | |
((= y 1) 2) | |
(else (A (- x 1) | |
(A x (- y 1)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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)))))) |
OlderNewer