This file contains hidden or 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
;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)))) |
This file contains hidden or 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
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: |
This file contains hidden or 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
;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)))))) |
This file contains hidden or 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
;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)) |
This file contains hidden or 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
; 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 |
This file contains hidden or 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
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" |
This file contains hidden or 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
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') | |
This file contains hidden or 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
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) |
This file contains hidden or 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/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)") |
This file contains hidden or 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
(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) |
OlderNewer