Skip to content

Instantly share code, notes, and snippets.

View samth's full-sized avatar

Sam Tobin-Hochstadt samth

View GitHub Profile
#lang racket
(require racket/unsafe/ops)
(define v (vector 0))
(unsafe-vector-ref v 50)
#lang typed/racket
(require/typed 2htdp/image
[#:opaque Image image?]
[circle (Number String String -> Image)])
@samth
samth / braunc.rkt
Created May 26, 2014 07:48
Random Braun trees
#lang racket
(struct node (x l r) #:transparent)
(define/match (size t)
[(#f) 0]
[((node x l r)) (+ 1 (size l) (size r))])
(define braun/c
(flat-rec-contract braun/c
(or/c #f
#lang racket
(define N 100000000)
(define K 50000000)
(time
(for/fold ([c 0]) ([i (in-range N)] #:break (not c))
(if (= i K)
#f
(add1 c))))
#lang typed/racket/base
(require racket/cmdline)
(: opt-verbose-mode (Parameterof Boolean))
(define opt-verbose-mode (make-parameter #f))
(: opt-max-size (Parameterof Real))
(define opt-max-size (make-parameter 0))
#lang typed/racket
#|
The paint-by-numbers-canavas% class accepts two initalization
arguments. They must be lists of lists of numbers and they must be the
same length. paint-by-numbers-canvas% objects accepts four methods:
set-rect : (int int (union 'on 'off 'unknown) -> void)
Sets the grid point specified by the first two arguments to the third.
The coordinates are from the top-left and the x coordinate comes first.
#lang racket
(require "foo.rkt")
(define ns (make-base-namespace))
(define v*
(let ()
(parameterize ([current-namespace ns])
(dynamic-require "foo.rkt" 'v))))
(x? v*) ;; should be #f
#lang racket/base
(define-struct contract-property [ name
first-order
projection
stronger
generate
exercise
val-first-projection
list-contract? ]
#lang racket/base
(define (average l)
(define len (length l))
(define sum (apply + l))
(display (/ len l)))
(average (list 1 2 3 400 500 600))
#lang racket
(define (mandelbrot/old iterations x y n)
(let ([ci (- (/ (* 2.0 y) n) 1.0)]
[cr (- (/ (* 2.0 x) n) 1.5)])
(let loop ([i 0] [zr 0.0] [zi 0.0])
(if (> i iterations)
i
(let ([zrq (* zr zr)]
[ziq (* zi zi)])