module Data.SBV.Examples.Puzzles.PowerSet where
import Data.SBV
genPowerSet :: [SBool] -> SBool
genPowerSet = bAll (.<= (true :: SBool))
powerSet :: [Word8] -> IO ()
powerSet xs = do putStrLn $ "Finding all subsets of " ++ show xs
res <- allSat $ mapM (const free_) [1..n] >>= output . genPowerSet
cnt <- displayModels disp res
putStrLn $ "Found: " ++ show cnt ++ " subset(s)."
where n = length xs
disp i ss
| length ss /= n = error $ "Expected " ++ show n ++ " results; got: " ++ show (length ss)
| True = putStrLn $ "Subset #" ++ show i ++ ": " ++ show (concat (zipWith pick ss xs))
pick True a = [a]
pick False _ = []