Skip to content

Instantly share code, notes, and snippets.

@dmalikov
Created July 9, 2012 22:29
Show Gist options
  • Save dmalikov/3079454 to your computer and use it in GitHub Desktop.
Save dmalikov/3079454 to your computer and use it in GitHub Desktop.
Algorithms: design and analysis I, exercise5 (week5)
{-# 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
@supki
Copy link

supki commented Jul 10, 2012

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment