Skip to content

Instantly share code, notes, and snippets.

@aoeuidht
aoeuidht / gist:3978427
Created October 30, 2012 05:13
SICP Exercise 1.12 -- Pascal's triangle
;The following pattern of numbers is called Pascal's triangle
(defun pascal_x_y (x y)
(if (or (= y 0) (= x y))
1
(+ (pascal_x_y (- x 1) (- y 1))
(pascal_x_y (- x 1) y))))
(defun draw_line (n)
(loop for idx from 0 to n do
(prin1 (pascal_x_y n idx))
@aoeuidht
aoeuidht / gist:3973003
Created October 29, 2012 11:14
1.11 of sicp
;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.
; Write a procedure that computes f by means of an iterative process.
(defun func_f (n)
(if (< n 4) n
(+ (func_f (- n 1))
(* 2 (func_f (- n 2)))
(* 3 (func_f (- n 3))))))
@aoeuidht
aoeuidht / gist:3946032
Created October 24, 2012 13:24
how Opera xhrproxy handle post params
if request.method == 'POST':
fields = request.GET['_proxy_fields'].split(',')
params = {}
for field in fields:
if len(field) == 0: continue
params[field] = request.POST[params]
if request.method == 'POST':
data = urllib.urlencode(params)
else:
@aoeuidht
aoeuidht / gist:3728553
Created September 15, 2012 15:52
SICP Exercise 1.3
;Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
(define (sum_squares_top2 c1 c2 c3)
(+
(square max(c1 c2))
(square max((min c1 c2) c3))))