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
// | |
// tries.c | |
// chitchat | |
// | |
// Created by Ben Oliver on 06/11/15. | |
// Copyright © 2015 Ben Oliver. All rights reserved. | |
// | |
// assume that we allow 8 char sequences from an alphabet of 26 characters | |
// there are 26 ^ 8 possible sequences 208,827,064,576 |
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
class Memoize(object): | |
def __init__(self, f): | |
self.f = f | |
self.computed = {} | |
def __call__(self, *args): | |
xs = self.computed.get(args) | |
if xs : | |
return xs |
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 memoize(f): | |
computed = {} | |
def memoized(*args): | |
xs = computed.get(args) | |
if xs : | |
return xs | |
else : | |
value = f(*args) |
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
import java.util.Random; | |
/** | |
* Created by boliver on 03/06/15. | |
*/ | |
public class Main { | |
public static void main(String args[]) { | |
Container value = new Container(); |
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
(define (make-balance) | |
(let ((balance 0)) | |
(define add-method | |
(lambda (value) (set! balance (+ balance value)))) | |
(define get-method | |
(lambda () balance)) | |
(define sub-method | |
(lambda (value) | |
(if (<= value balance) | |
(set! balance (- balance value)) |
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
(define (make-counter-1) | |
(let ((counter 0)) | |
(lambda () | |
(set! counter (+ counter 1)) | |
counter))) | |
(define (make-counter-2) | |
(define counter 0) | |
(lambda () | |
(set! counter (+ counter 1)) |
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
> (define (foo) | |
(let ((xs '(1 2 3))) | |
(define (f) | |
(set! xs 0)) | |
(f) | |
xs)) | |
> (foo) | |
0 |
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
;; delay and force are defined in r5rs, | |
;; but if we were defining them for ourselves | |
(define-syntax my-delay | |
(syntax-rules () | |
((_ expr) | |
(lambda () expr)))) | |
(define (my-force expr) |
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
(require r5rs) | |
(define xs '(1 2 3 4 5)) ;; xs is a list of numbers | |
xs | |
(set! xs "a list of numbers") ;; xs is now "a list of numbers" | |
xs | |
(define (update-1 arg) | |
(set! arg "this has only changed the value of 'arg' within 'update-1'") | |
arg) |
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
(require r5rs) | |
(define (set-nth! n xs x) | |
(cond ((null? xs) (error "index out of bounds")) | |
((eq? n 0) (set-car! xs x)) | |
(#t (set-nth! (- n 1) (cdr xs) x)))) | |