Created
July 9, 2012 22:29
-
-
Save dmalikov/3079454 to your computer and use it in GitHub Desktop.
Algorithms: design and analysis I, exercise5 (week5)
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 | |
main = do | |
h ← readHashSet . head =<< getArgs | |
putStrLn $ concatMap (show . (\x → if x then 1 else 0) . getAny . canBeProduced h) | |
[231552,234756,596873,648219,726312,981237,988331,1277361,1283379] | |
readHashSet ∷ FilePath → IO (HS.HashSet Int) | |
readHashSet φ = HS.fromList . map fst . mapMaybe BSC.readInt . BSC.lines <$> BSC.readFile φ | |
canBeProduced ∷ HS.HashSet Int → Int → Any | |
canBeProduced h v = foldMap (\α → Any $ HS.member (v - α) h) h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍