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 NLP.Tokenize | |
import Data.MarkovChain | |
import System.Random | |
text = "The protagonist of Hamlet is Prince Hamlet of Denmark, son of the recently deceased King Hamlet, and nephew of King Claudius, his father's brother and successor. Claudius hastily married King Hamlet's widow, Gertrude, Hamlet's mother. Denmark has a long-standing feud with neighbouring Norway, and an invasion led by the Norwegian prince, Fortinbras, is expected.\nThe play opens on a cold winter midnight on \"platform before the castle\" of Elsinore, the Danish royal castle. The sentry Francisco is keeping trusty guard when two figures appear in the darkness. Bernardo, a sentry come to replace Francisco, calls out, \"Who's there?\" Francisco replies, \"Nay, answer me. Stand and unfold yourself.\" Friendly identity proven, Francisco retires to bed. En route, Francisco encounters Horatio and Marcellus who are coming to visit Bernardo. Bernardo and Marcellus discuss the recent appearance of a curious intruder which they describe as a \"dread |
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 Roll where | |
{-- | |
Okay, shoot! Fell asleep while composing a problem; sorry for the delay! | |
So, this one is an easy one. We get a little Forth'y'. This is from P19 | |
of the P99 problem-set. | |
--} |
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 Data.Deque where | |
{-- | |
The following sets of problems over the next few days get their inspiration | |
from some of the problems from the P99, or Ninety-Nine Prolog Problems | |
published by Werner Hett. | |
Create a traversable data type, let’s call it Deque a (‘Deque’ meaning: | |
‘double-ended queue’) such that the operation |
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
(************************************) | |
(* Never edit options files when *) | |
(* the daemon is running *) | |
(************************************) | |
(* SECTION : Main *) | |
(* Main options *) | |
(************************************) |
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.List.HT | |
import Data.List | |
import System.Random.Shuffle | |
import Control.Monad.Random.Class | |
import qualified Data.Set as S | |
bitStringsN1s :: Int -> Int -> [[Int]] | |
bitStringsN1s n maxLength = do | |
bitString <- replicateM maxLength [0, 1] |
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 MatchingSub where | |
import Data.List | |
-- | Submit these to MissingH | |
dropWhilePrefixList :: ([a] -> Bool) -> [a] -> [a] | |
dropWhilePrefixList = go [] | |
where go :: [a] -> ([a] -> Bool) -> [a] -> [a] | |
go _ _ [] = [] | |
go acc p rest@(x : xs) = if (not . p) acc then rest else go (acc ++ [x]) p 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
module NGrams where | |
import Data.Char | |
import Data.List | |
-- | Given a String, compute all the n letters n-grams of its words (excluding all non alphanums characters). | |
-- Word separations matter. | |
-- | |
-- Example: | |
-- | |
-- >>> lettersNGrams 3 "Hello, world!" |
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
nothing = lambda {|default, junk| default} | |
just = lambda {|x| lambda{|junk, f| f[x]}} | |
maybe = lambda {|default, f, m| m[default, f]} | |
show_maybe = lambda {|m| maybe['nothing', lambda {|x| "just[#{x}]"}, m]} | |
plus_2 = lambda {|x| maybe[nothing, lambda {|x| just[x + 2]}, x]} | |
# >>> x = nothing | |
# >>> y = just[5] | |
# >>> maybe[false, lambda {|x| true}, y] | |
# true | |
# >>> maybe[false, lambda {|x| true}, x] |
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
""" | |
Either in Python. | |
""" | |
def left(x): | |
""" | |
Haskell: Left 5 | |
Python: left(5) | |
""" |
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
swap (x,y) = (y,x) | |
alternate xs ys = Prelude.concat (zipWith (\x y -> [x, y]) xs ys) | |
-- | Swap then interleave the swapped elements | |
-- >>> interleaveSwapped [(1,2),(2,3)] | |
-- [(1,2),(2,1),(2,3),(3,2)] | |
interleaveSwapped = alternate <*> map swap |