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
# why do blocks even exist? | |
def fibs1 | |
a, b = 0, 1 | |
while b < 1000 | |
yield b | |
a, b = b, a + b | |
end | |
end | |
# it seems like "yield" is just syntax for "invoke this weird callback" |
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 __future__ import division | |
import sys | |
from random import SystemRandom | |
# A list of unicode combining characters | |
COMBINING = [unichr(c) for c in xrange(0x300, 0x370)] | |
ZalgoError = KeyError |
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
public class Thunks { | |
/** | |
* Interface which represents unary functions. Can be anonymously | |
* instantiated to simulate lambdas. | |
*/ | |
public static interface Fn<A, B> { | |
public B call(A arg); | |
} | |
/** |
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
import Data.Either | |
import System.Random | |
-- |An association list mapping random variable outputs to their | |
-- probabilities, which should add up to 1. | |
type ProbMass a = [(a, Double)] | |
-- |Given a uniform random number in [0, 1) and a probability mass function | |
-- (PMF) describing the probabilities of various outcomes of a random | |
-- variable X, give a random outcome. |
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
(* Type of natural numbers *) | |
type nat = Zero | |
| Succ of nat ;; | |
exception Undefined ;; | |
type comparison = LT | |
| EQ | |
| GT ;; |
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
API_HANDLERS = {} | |
def register_handler(func, name=None): | |
if name is None: | |
name=func.__name__ | |
API_HANDLERS[name] = func | |
return func | |
def dispatch(name, request): | |
return API_HANDLERS[name](request) |
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
#lang racket | |
; Solution to Project Euler problem #23 | |
(require racket/set) | |
; Predicate to check if m | n | |
(define (divides? m n) | |
(= 0 (modulo n m))) |
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 functional import fun | |
from itertools import imap, ifilter, takewhile, count | |
@fun(2) | |
def add(x,y): return x + y | |
# Here I define a function which takes a string and shows what it evaluates to. | |
@fun(1) | |
def evalPrint(s): | |
print "%s -> %s" % (s, eval(s)) |
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
#include "dict.h" | |
/* Initializes the hash table at table. | |
* Arguments: | |
* | |
* init_size: the initial number of chains in the hash table. If 0, defaults | |
* to a hardcoded value. | |
* key_hash: a hashing function that operates on keys | |
* key_eq: function which returns nonzero iff two keys are equal. | |
* |
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
module Main (main) where | |
import Control.Monad | |
import Data.Char | |
import System.IO | |
import System.Environment | |
import System.Random | |
import System.Exit |