This file contains hidden or 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 Control.Monad | |
import Data.Ratio | |
data FakeRatio = FakeRatio { numr :: Int, denom :: Int} deriving (Show) | |
data SBTriple = SBTriple { left :: FakeRatio, | |
mid :: FakeRatio, | |
right :: FakeRatio} | |
data Directions = TLeft | TRight deriving (Show) |
This file contains hidden or 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 Control.Monad | |
data LSymbol = LRule Char | LDeriv String | |
type Alphabet = [LSymbol] | |
type Axiom = [LSymbol] | |
-- a production is a finite mapping of LSymbol -> LSymbol | |
-- if no production exists for a given LSymbol on the LHS of a Production |
This file contains hidden or 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 Control.Monad | |
enumerate xs = zip [1..] xs | |
dlists :: [a] -> [(a, [a])] | |
dlists xs = [(x, [y | (j, y) <- enumerate xs, j /= i]) | (i, x) <- enumerate xs] | |
permute (x:y:[]) = [y:x:[], x:y:[]] | |
permute xs = let difflist = dlists xs | |
in join [map (i:) (permute d) | (i, d) <- difflist] |
This file contains hidden or 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 LSystem where | |
import Control.Monad | |
data LSymbol = LRule Char | LDeriv String | |
type Alphabet = [LSymbol] | |
type Axiom = [LSymbol] |
This file contains hidden or 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 GADTs, FlexibleInstances #-} | |
import Graphics.Gloss | |
import Graphics.Gloss.Data.Vector | |
import LSystem | |
data PlantInstruction a where | |
DrawForward :: PlantInstruction a | |
TurnLeft :: (Show a, Num a) => a -> PlantInstruction a | |
TurnRight :: (Show a, Num a) => a -> PlantInstruction a |
This file contains hidden or 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.List.Split | |
import Data.Char | |
import qualified Data.Map as Dm | |
import Control.Applicative | |
ngrams' n len xs = let next = (take n xs) | |
in case len == n of | |
False -> (toLower <$> next) : (ngrams' n (len - 1) $ drop 1 xs) | |
_ -> return xs | |
ngrams n xs = ngrams' n (length xs) xs |
This file contains hidden or 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
select [] = [] | |
select (x : xs) = (x, xs) : map (fmap (x :)) (select xs) | |
perm2 ks = [[x,y] | (x, ys) <- select ks, y <- ys] | |
permute 2 xs = perm2 xs | |
permute n xs = join [[x : p | p <- (permute (n-1) ys)] | (x,ys) <- select xs] |
This file contains hidden or 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 Control.Monad | |
data AlienSymbol = (:@:) | (:#:) | (:!:) | (:^:) | (:%:) | (:*:) | (:&:) deriving (Ord, Eq, Enum) | |
data AlienNumber = AN [AlienSymbol] deriving (Ord, Eq) | |
trim n = let dropped = dropWhile (==(:@:)) n in | |
case dropped of | |
[] -> [(:@:)] | |
_ -> dropped |
This file contains hidden or 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 Control.Monad | |
coprime a b = gcd a b == 1 | |
istriple m n = coprime m n && odd (m - n) && (m > n) && m > 0 && n > 0 | |
triple m n k = | |
let a = k * (m^2 - n^2) | |
b = k * (2*m*n) | |
c = k * (m^2 + n^2) | |
in [a,b,c] |
This file contains hidden or 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
-- my implementation of this: http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf | |
import qualified Data.PSQueue as DQ | |
insertThenDel k p pq = DQ.deleteMin $ DQ.insert k p pq | |
minPriority pq = | |
case DQ.findMin pq of | |
(Just m) -> | |
let mp = DQ.prio m |
OlderNewer