Skip to content

Instantly share code, notes, and snippets.

View mdunsmuir's full-sized avatar

Michael Dunsmuir mdunsmuir

  • Seattle
View GitHub Profile
module Main where
import Control.Monad (when)
import System.Environment (getArgs)
import Data.List (intersperse)
fibo :: [Int]
fibo = 0 : 1 : zipWith (+) fibo (tail fibo)
hotDogsOnDay :: Int -> Int
function fix(f) {
return function(x) {
return f(x)(fix(f));
}
}
var fac = function(x) {
if(x == 1) {
return function(_) {
return 1;
# 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
{-# 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
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)
@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
@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)
{-# LANGUAGE MultiParamTypeClasses,
FunctionalDependencies,
FlexibleInstances #-}
module StateT (
--StateT, runStateT,
State, runState,
MonadState,
module Control.Applicative,
module Control.Monad,
-- 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
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