Skip to content

Instantly share code, notes, and snippets.

View mdunsmuir's full-sized avatar

Michael Dunsmuir mdunsmuir

  • Seattle
View GitHub Profile
module PascalsTriangle (pascalsTriangle) where
import Control.Applicative
import Test.QuickCheck
pascalsTriangle :: [[Int]]
pascalsTriangle = [1] : map row pascalsTriangle
where row prev = zipWith (+) (0 : prev) (prev ++ [0])
-- quickcheck stuff
-- common
data Fix a = Fx (a (Fix a))
unfix :: Fix a -> a (Fix a)
unfix (Fx f) = f
type Algebra f a = f a -> a
cata :: Functor f => (f a -> a) -> Fix f -> a
{-# LANGUAGE MultiParamTypeClasses,
FunctionalDependencies,
FlexibleInstances #-}
module StateT (
--StateT, runStateT,
State, runState,
MonadState,
module Control.Applicative,
module Control.Monad,
@mdunsmuir
mdunsmuir / Trie.hs
Last active August 29, 2015 14:13
given an input 'dictionary' (a list of words) and a string, determine whether the string is an arbitrary concatenation of the words in the dictionary
module Trie (
Trie,
empty,
fromList,
insert,
prefixesFor
) where
import Data.Maybe
import Data.List (foldr)
@mdunsmuir
mdunsmuir / Hudooku.hs
Last active August 29, 2015 14:14
Sudoku
{-# LANGUAGE TupleSections #-}
import System.Environment
import Control.Monad
import qualified Data.Attoparsec.Text as P
import Data.Maybe
import Data.List
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import qualified Data.Map as M
import System.Environment
import Control.Exception
import Control.Monad
import Network.Socket
main = do
args <- getArgs
case args of
[host] -> catch (displayIPs host) $ \e -> do
let err = show (e :: IOException)
{-# LANGUAGE RankNTypes #-}
import Data.Functor.Identity
import Graphics.Gloss
-- * types
type Lens s a = forall f. Functor f => (a -> f a) -> s -> f s
ix :: Int -> Lens [a] a
# Generated by ffi_gen. Please do not change this file by hand.
require 'ffi'
module Slurm
extend FFI::Library
ffi_lib "slurm"
def self.attach_function(name, *_)
begin; super; rescue FFI::NotFoundError => e
function fix(f) {
return function(x) {
return f(x)(fix(f));
}
}
var fac = function(x) {
if(x == 1) {
return function(_) {
return 1;
tape = {}
tape.default = 0
ptr = 0
tape[ptr] += 13
while tape[ptr] != 0
tape[ptr] -= 1
tape[ptr + 1] += 2
tape[ptr + 4] += 5
tape[ptr + 5] += 2
tape[ptr + 6] += 1