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
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
(* 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
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
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
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
# 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
import Data.Word | |
import Data.List | |
import Control.Monad.State.Strict | |
import Control.DeepSeq | |
data EmitterState = EmitterState { | |
emNextLabel :: Int | |
} deriving (Read, Show, Eq, Ord) | |
instance NFData EmitterState where |
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 Stack where | |
import Control.Arrow | |
class List a | |
-- Use pairs to represent a cons list which can be statically checked | |
instance List () | |
instance List b => List (a, b) |
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
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, ScopedTypeVariables #-} | |
module TuringMachine where | |
import Control.Monad.State.Lazy | |
import Data.Array.ST | |
import Data.Array | |
import Data.Default | |
import Control.Monad.ST | |
import Control.Arrow ((&&&)) |