This file contains 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
{- | |
A direct implementation of a prime sieve ... | |
-} | |
module ArrSieve | |
( Sieve(unSieve) | |
, isPrime | |
, unsafeIsPrime | |
, sieve | |
) where |
This file contains 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
{-| | |
A naive implementation of hash chains; can be used for | |
one-time password systems. | |
See <https://en.wikipedia.org/wiki/S/KEY>. | |
-} | |
module HashChain ( | |
HashChain(_size, _hash) | |
, next | |
, init_chain |
This file contains 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 Timed (timed) where | |
import Control.Concurrent | |
-- | Fork a process that should return some value within some time limit. | |
-- | |
-- > timed 10 (threadDelay 100 >> return "takes too long") = Nothing | |
-- > timed 100 (threadDelay 10 >> return "in time") = Just "in time" | |
timed :: Int -- microseconds | |
-> IO a |
This file contains 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
{-| | |
General 'length' for any 'Foldable' structure. | |
> foldLength [undefined, undefined] = 2 | |
-} | |
module FoldLength (foldLength1, foldLength2) where | |
import Data.Functor | |
import qualified Data.Foldable as F |
This file contains 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 Volume (runTest) where | |
import Control.Monad (forM_) | |
import qualified Test.QuickCheck as QC | |
-- | Volume values. | |
-- | |
-- Values of this type are always in the range 0-100. | |
-- | |
-- Arithmetic on volumes has the property that: |
This file contains 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
library(XML) | |
url <- "http://eu.battle.net/sc2/en/profile/2007578/1/joachifm" | |
scrape.matchhistory <- function(profile.url) { | |
url <- paste(profile.url, "/matches", sep="") | |
doc <- htmlTreeParse(url, useInternalNodes=T) | |
thead <- xpathSApply(doc, "//*/table[@class='data-table']/thead/tr/th", xmlValue) | |
tbody <- xpathSApply(doc, "//*/table[@class='data-table']/tbody/tr/td", compose(trim, xmlValue)) | |
m <- matrix(tbody, ncol=length(thead), byrow=T) |
This file contains 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 (find, unfoldr) | |
main = interact (unlines . map (uncurry fmt) . zip [1..] . map solve . parse) | |
where fmt n (Just (x, y)) = "Case #" ++ show n ++ ": " ++ unwords [show x, show y] | |
fmt _ Nothing = "" | |
solve (c, xs) = go $ zip [1..] xs | |
where go ((i, n):ys) = | |
case find (\(_, n') -> n' + n == c) ys of |
This file contains 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 Alternate where | |
import Control.Arrow (Arrow, (***)) | |
import Test.QuickCheck | |
-- | Transform a list into a list of pairs. | |
-- Lazy consumer. | |
pairs :: [a] -> [(a, a)] | |
pairs (x:y:z) = (x, y) : pairs (y:z) | |
pairs _ = [] |
NewerOlder