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
# -*- coding: utf-8 -*- | |
""" | |
Builds epub book out of Paul Graham's essays: http://paulgraham.com/articles.html | |
Author: Ola Sitarska <[email protected]> | |
This script requires python-epub-library: http://code.google.com/p/python-epub-builder/ | |
""" | |
import re, ez_epub, urllib2, genshi |
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
files = file('54.txt').readlines() | |
hands = [h.replace('\n','') for h in files] | |
def result(): | |
dicts = {0:0, 1:0} | |
for i in range(1000): | |
h1, h2 = split_hand(hands[i]) | |
dicts[who_won(h1,h2)] +=1 | |
return dicts |
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
def pascal(n): | |
if n == 1: | |
return [1] | |
else: | |
x = pascal(n-1) | |
return [1] + [x[i]+x[i-1] for i in range(1,len(x))] + [1] | |
" seems like learning functional language is helpful :) " |
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
from collections import Counter | |
from collections import defaultdict | |
def frequency1(lst): | |
return [(lst.count(s), s) for s in set(lst)] | |
def frequency2(lst): | |
return dict((s, lst.count(s)) | |
for s in set(lst)) |
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 fib3 | |
(letrec([memo null] ; list of pairs (arg . result) | |
[f (lambda (x) | |
(let ([ans (assoc x memo)]) | |
(if ans | |
(cdr ans) | |
(let ([new-ans (if (or (= x 1) (= x 2)) | |
1 | |
(+ (f (- x 1)) | |
(f (- x 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 (ps1 x) | |
(if (equal? 0 x) | |
0 | |
(if (or (equal? 0 (modulo x 3)) (equal? 0 (modulo x 5))) | |
(+ x (ps1 (- x 1))) | |
(ps1 (- x 1))))) | |
(ps1 999) |
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
"""Embedded in this block of text is the password for level 2. | |
The password is the longest substring that is the same in reverse. | |
As an example, if the input was "I like racecars that go fast" | |
the password would be "racecar". | |
challenge from http://challenge.greplin.com/ | |
""" | |
text = """FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalNowweareengagedinagreahtcivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingra |
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
""" | |
1) Win: If you have two in a row, play the third to get three in a row. | |
2) Block: If the opponent has two in a row, play the third to block them. | |
3) Fork: Create an opportunity where you can win in two ways. | |
4) Block Opponent's Fork: | |
5) Center: Play the center. | |
6) Opposite Corner: If the opponent is in the corner, play the opposite corner. | |
7) Empty Corner: Play an empty corner. | |
8) Empty Side: Play an empty side. | |
""" |
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 (expand-row p) | |
(cons (car p) (expand-row-rest p))) | |
(define (expand-row-rest p) | |
(if (null? (cdr p)) (list 1) | |
(cons (+ (car p) (cadr p)) | |
(expand-row-rest (cdr p))))) | |
(define (pascals-row n) | |
(if (= n 0) (list 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 (getFinalAmount initial res) | |
(define (helper total bet n) | |
(cond [(or (> (+ 1 n) (string-length res)) (> bet total)) total] | |
[(eq? (string-ref res n) #\L) (helper (- total bet) (* 2 bet) (+ n 1))] | |
[#t (helper (+ amount total) 1 (+ n 1))])) | |
(helper initial 1 0)) |
OlderNewer