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)) |
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 getFinalAmount(initial, res): | |
def helper(total, bet, n): | |
return (total if n > len(res) - 1 or bet > total else | |
helper(total-bet, bet*2, n+1) if res[n] == 'L' else | |
helper(total+bet, 1, n+1)) | |
return helper(initial, 1, 0) |
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
getFinal initial res = helper initial 1 0 | |
where helper total bet n = if n > (length res) - 1 || bet > total. | |
then total | |
else if res !! n == 'L'. | |
then helper (total-bet) (bet*2) (n+1) | |
else helper (total+bet) 1 (n+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
fun getFinal init res = | |
let | |
fun helper total bet n = | |
case n+1 > size res of | |
true => total | |
| _ => if String.sub (res, n) = #"L" | |
then helper (total-bet) (bet*2) (n+1) | |
else helper (total+bet) 1 (n+1) | |
in | |
helper init 1 0 |
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 dvr_remote(s, width): | |
x = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_' | |
rows = [x[i:i+width] for i in range(0, 27, width)] | |
s = 'A' + s.replace(' ', '_') | |
DIC = dict((char, (i, pos)) | |
for i in range(len(rows)) | |
for (pos, char) in enumerate(rows[i])) | |
def helper(current, next): | |
row1, col1 = DIC[current] |