module Data.SBV.Examples.Puzzles.PowerSet where
import Data.SBV
genPowerSet :: [SBool] -> SBool
genPowerSet = bAll isBool
where isBool x = x .== true ||| x .== false
powerSet :: [Word8] -> IO ()
powerSet xs = do putStrLn $ "Finding all subsets of " ++ show xs
res <- allSat $ mkFreeVars n >>= return . 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 _ = []