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 UnicodeSyntax #-} | |
import Control.Applicative ((<$>)) | |
import Data.Foldable (foldMap) | |
import Data.Maybe (mapMaybe) | |
import Data.Monoid (Any(..)) | |
import System.Environment (getArgs) | |
import qualified Data.ByteString.Lazy.Char8 as BSC | |
import qualified Data.HashSet as HS |
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 UnicodeSyntax #-} | |
module Graph where | |
import Control.Applicative ((<$>)) | |
import Control.Monad (replicateM) | |
import System.Random (randomRIO) | |
import qualified Data.IntMap as IntMap | |
type Graph = IntMap.IntMap [Int] |
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 UnicodeSyntax #-} | |
import Control.Arrow ((***)) | |
import Control.Monad (join) | |
merge ∷ Ord α => [α] -> [α] -> [α] | |
merge a [] = a | |
merge [] a = a | |
merge xlist@(x:xs) ylist@(y:ys) | x < y = x : merge xs ylist | |
| otherwise = y : merge xlist ys |
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 UnicodeSyntax #-} | |
module Inversions (inversions) where | |
inversions ∷ Ord α ⇒ [α] → Int | |
inversions = fst . inversions' | |
where | |
inversions' list@(_:_:_) = (leftInvs + rightInvs + splitInvs, sortedList) | |
where (leftInvs, leftSortedList) = inversions' leftList | |
(rightInvs, rightSortedList) = inversions' rightList | |
(splitInvs, sortedList) = mergeInvs leftSortedList rightSortedList |
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 GeneralizedNewtypeDeriving #-} | |
module Elements | |
( aElements, bElements, sElements | |
) where | |
import Control.Applicative (liftA2) | |
import Types |
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.Arrow ((***), (&&&)) | |
import Control.Monad ((<=<), forM_, join, liftM, liftM2, when) | |
import Data.Maybe (fromMaybe) | |
import Kludges | |
import Network.Lastfm.API.Artist (getInfo) | |
import Network.Lastfm.Types | |
import Text.Printf | |
import Text.XML.Light | |
import qualified Network.Lastfm.API.Library as L |
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.Applicative ((<$>)) | |
import Control.Monad ((<=<), forever, liftM, liftM2) | |
import Data.Function (on) | |
import Data.Maybe (fromMaybe) | |
import Data.Time.Format (formatTime) | |
import Data.Time.LocalTime (getZonedTime) | |
import GHC.Conc.IO (threadDelay) | |
import Network.Lastfm.Types | |
import Network.Lastfm.API.User | |
import System.Directory (getHomeDirectory) |
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.Numbers.Primes (primeFactors) | |
import Data.List (group, nub, sort) | |
import Control.Arrow ((&&&)) | |
import PECore | |
squarefree :: Integer -> Bool | |
squarefree = all ((< 2) . snd) . map ((&&&) head length) . group . primeFactors | |
numFromPascalTriangles :: Integer -> [Integer] | |
numFromPascalTriangles n = nub . sort . concat . map (\x -> map (combinations x) $ [0..x]) $ [0..n-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
import PECore (numToList, listToNum) | |
import Control.Monad (ap) | |
import Data.List (sort) | |
bouncy :: (Num a, Ord a) => [a] -> Bool | |
bouncy = not . (\x -> all (>=0) x || all (<=0) x) . map (uncurry (-)) . ap zip tail | |
bouncyNumber :: Integer -> Bool | |
bouncyNumber = bouncy . numToList |
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 PECore (fastPow) | |
import Data.Numbers.Primes (primes) | |
import Control.Arrow ((&&&)) | |
main = print . sum . take 40 . map fst . filter ( (== 1) . snd) . map ( (&&&) id (fastPow 10 (10^9)) ) . dropWhile (<= 3) $ primes |