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
{-# LANGUAGE LambdaCase, TupleSections, TemplateHaskell, DeriveFunctor, DeriveFoldable, DeriveTraversable #-} | |
import qualified Data.IntMap.Strict as IM | |
import qualified Data.IntSet as IS | |
import qualified Data.Foldable as F | |
import Control.Applicative | |
import Control.Lens | |
import Control.Monad.State.Strict | |
import Debug.Trace |
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 qualified Data.Vector as V | |
import qualified Data.Vector.Unboxed as UV | |
import qualified Data.ByteString.Char8 as B | |
import Data.Ix | |
import Text.Printf | |
import Data.List | |
import Data.Ord | |
import System.Environment | |
import Data.Bits |
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
{- | |
Copyright (C) 2014 András Kovács | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
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
{-# LANGUAGE LambdaCase #-} | |
import Data.List | |
import Control.Arrow | |
import Control.Lens | |
inv = [("map",9,150), ("compass",13,35), ("water",153,200), ("sandwich",50,160), | |
("glucose",15,60), ("tin",68,45), ("banana",27,60), ("apple",39,40), | |
("cheese",23,30), ("beer",52,10), ("cream",11,70), ("camera",32,30), | |
("tshirt",24,15), ("trousers",48,10), ("umbrella",73,40), |
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 Combinatorics (powerset, combsOf, perms) where | |
powerset :: [a] -> [[a]] | |
powerset (x:xs) = let xs' = powerset xs in xs' ++ map (x:) xs' | |
powerset [] = [[]] | |
combsOf :: Int -> [a] -> [[a]] | |
combsOf n _ | n < 1 = [[]] | |
combsOf n (x:xs) = combsOf n xs ++ map (x:) (combsOf (n - 1) xs) | |
combsOf _ _ = [] |
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
coinChange :: [Int] -> [Int] | |
coinChange = foldr go (1: repeat 0) where | |
go coin xs = xs' where | |
(a, b) = splitAt coin xs | |
xs' = a ++ zipWith (+) xs' b | |
main = print $ coinChange [1,5,10,25,50] !! 100 -- prints 292 |
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
{-# LANGUAGE LambdaCase, DeriveFunctor #-} | |
import Prelude hiding (take, head) | |
import Control.Monad | |
import Control.Monad.Trans | |
data ListT' m a = Nil | Cons a (ListT m a) deriving (Functor) | |
newtype ListT m a = ListT {runListT :: m (ListT' m a)} deriving (Functor) | |
instance Monad m => Monad (ListT m) 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
{-# LANGUAGE | |
LambdaCase, DeriveFunctor, FlexibleContexts, | |
RankNTypes, TemplateHaskell, NoMonomorphismRestriction #-} | |
-- golfing the state monad with free | |
import Control.Monad | |
import Control.Monad.Free | |
import Control.Monad.Free.TH | |
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
{-# LANGUAGE | |
TemplateHaskell, LambdaCase, MultiParamTypeClasses, | |
FlexibleInstances, FunctionalDependencies #-} | |
import Control.Applicative | |
import Control.Lens | |
import Control.Lens.Extras | |
data Item = Simple {_sellIn :: Int, _quality :: Int, _itemName :: String} | |
| Conjured {_sellIn :: Int, _quality :: Int, _itemName :: String} |
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
{-# LANGUAGE | |
DataKinds, GADTs, TypeFamilies, | |
ScopedTypeVariables, LambdaCase, | |
TemplateHaskell, StandaloneDeriving, | |
DeriveFunctor, DeriveFoldable, DeriveTraversable, TypeOperators #-} | |
import Data.Singletons.TH | |
import Data.Foldable (Foldable) | |
import Data.Traversable (Traversable) |