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
{-# 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 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 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.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 | |
( Distance, Graph, Vertex | |
, fromList, findShortestPath, findShortestPaths, findShortestPaths_ | |
) where | |
import Control.Monad (when) | |
import Control.Monad.Reader (Reader, ask, runReader) | |
import Control.Monad.State (StateT, execStateT, get, put) | |
import Data.Function (on) |
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
def palindrome? (string) | |
filtered = string.downcase.gsub(/\W/,'') | |
filtered.reverse == filtered | |
end | |
def count_words (sentence) | |
words = sentence.downcase.split(/\W/) | |
result = {} | |
words.uniq.select{ |w| !w.empty? }.each do |e| | |
result.store(e, words.count(e)) |
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 System.Environment (getArgs) | |
import Text.Regex.Posix ((=~)) | |
main ∷ IO () | |
main = do | |
pattern ← head <$> getArgs | |
mapM_ putStrLn =<< dropWhile (\α → not $ α =~ pattern) . lines <$> getContents |
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
octave:13> factorial 0 | |
ans = 1.2414e+61 | |
octave:14> factorial 1 | |
ans = 6.0828e+62 | |
octave:15> factorial 2 | |
ans = 3.0414e+64 | |
octave:16> factorial 10 | |
ans = | |
6.0828e+62 1.2414e+61 |
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
$> cabal-dev ghci | |
cabal-dev: user error (Warning: cannot determine version of /usr/bin/fake-ghc-cabal-dev : | |
"== GHC Arguments: Start ==\n--numeric-version\n== GHC Arguments: End ==\n" | |
cabal: ghcInvocation: the programVersion must not be Nothing | |
) |