Skip to content

Instantly share code, notes, and snippets.

@aoeuidht
aoeuidht / gist:5730331
Created June 7, 2013 15:58
exericse 1.32
(defun accumulate (combiner null-value term a next b)
(if (> a b)
null-value
(funcall combiner
(funcall term a)
(accumulate combiner null-value term (funcall next a) next b)))
)
(defun accumulate-iter (combiner null-value term a next b)
(defun iter (a result)
(if (> a b)
@aoeuidht
aoeuidht / gist:5729827
Created June 7, 2013 14:53
exericse 1.31
(defun product (term a next b)
(if (> a b)
1
(* (funcall term a)
(product term (funcall next a) next b))))
(defun product-iter (term a next b)
(defun iter (a result)
(if (> a b)
result
(defun cube (x) (* x x x))
(defun sum-iter (term a next b)
(defun iter (a result)
(if (> a b)
result
(iter (funcall next a) (+ result (funcall term a)))))
(iter a 0))
(defun simp-integral (f a b n)
@aoeuidht
aoeuidht / gist:5723282
Last active December 18, 2015 04:09
exericse 1.29
(defun sum (term a next b)
(if (> a b)
0
(+ (funcall term a)
(sum term (funcall next a) next b))))
(defun cube (x) (* x x x))
(defun integral (f a b dx)
(defun add-dx (x) (+ x dx))
(* (sum f
(+ a (/ dx 2.0))
@aoeuidht
aoeuidht / exericse-1.11.lisp
Last active December 17, 2015 20:49
exericse 1.11
(defun calc-f (n)
(if (< n 3)
n
(+ (calc-f (- n 1))
(* (calc-f (- n 2)) 2)
(* (calc-f (- n 3)) 3)
))
)
(defun calc-f (n)
@aoeuidht
aoeuidht / gist:5402272
Created April 17, 2013 06:50
generate json files in my documentation
#! /usr/bin/sbcl --script
(load "~/quicklisp/setup.lisp")
(with-open-file (*standard-output* "/dev/null" :direction :output
:if-exists :supersede)
(ql:quickload "cl-json"))
(defmacro rep-item (item rep-cnt)
`(loop for i from 1 to ,rep-cnt collect ,item))
(let ((gossip-item '((a . liszt)(c . msg1)(ts . 123456)))
(part-item '((nick . liszt)(uid . a1b2c3d4)(loc . "(1234,5678)")
def sigma(n):
return n and (n + sigma(n-1)) or 0
def sigma_tail(n, sum=0):
return n and sigma_tail((n-1), (n+sum)) or sum
print sigma(50)
print sigma_tail(50)
@aoeuidht
aoeuidht / gist:4143224
Created November 25, 2012 11:53
xhrproxy should support gbk encoding
def decode(s, encodings=('gbk', 'utf8', 'windows-1251', 'iso-8859-1')):
for encoding in encodings:
try:
return s.decode(encoding)
except UnicodeDecodeError:
pass
return s.decode('iso-8859-1', 'ignore')
@aoeuidht
aoeuidht / gist:4014719
Created November 5, 2012 01:25
xhrproxy still not working with 「content-type」 in _proxy_headers
curl -vvv -H "Content-Type: xml" -H "charset: utf8" -d"a=b" "http://netease-news.tv.opera.com/xhrproxy/?_proxy_fields=&_proxy_headers=content-type,charset&_proxy_url=http%3A//echo.opera.com"
@aoeuidht
aoeuidht / gist:3978843
Created October 30, 2012 07:45
SICP Exercise 1.17 -- fast-times
; Now suppose we include, together with addition,
; operations double, which doubles an integer,
; and halve, which divides an (even) integer by 2.
; Using these, design a multiplication procedure analogous to
; fast-expt that uses a logarithmic number of steps.
(defun fast_times (multiplicand multiplier)
(cond ((= multiplier 0) 0)
((even? multiplier)
(double (fast_times multiplicand (half multiplier))))
(else