Skip to content

Instantly share code, notes, and snippets.

@jocke-l
jocke-l / enum.py
Last active December 19, 2015 17:19
Dynamic enumration function
def enum(varnames, start=0):
return dict(zip(varnames, range(start, start + len(varnames))))
@jocke-l
jocke-l / hangman.hs
Last active December 17, 2015 12:09
Hangman in Haskell
module Main where
import System.Random
import Data.List (intersect)
import Prelude hiding (words)
import Text.Printf
obscure word letters = map hide word
where hide c
| c `elem` (' ' : letters) = c
@jocke-l
jocke-l / pi.hs
Last active December 15, 2015 11:59
A function that computes π
import Data.Number.CReal
piit accuracy = showCReal 100 (go 1 (1 / sqrt 2) (1 / 4) 1)
where go a b t p | (a - b) >= accuracy = let aa = (a + b) / 2
bb = sqrt (a * b)
tt = t - p * (a - aa)^2
pp = 2 * p
in go aa bb tt pp
| otherwise = (a + b)^2 / (4 * t)