Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Lib
- ( someFunc
- ) where
- type Card = (Char,Char) -- ('J','C'),('K','S'),etc
- type Statement = Bool -- True is truth, False is lied
- allcards :: [Card]
- allcards = do
- suit <- "HCDS"
- card <- "JQK"
- return (card,suit)
- -- is Jack of Clubs
- isJC :: Card -> Bool
- isJC (card,suit) = card == 'J' && suit == 'C'
- isnotJC :: Card -> Bool
- isnotJC x = not $ isJC x
- saidJC :: Card -> Statement -> Bool
- saidJC card statement = (isJC card && statement) || (isnotJC card && not statement)
- aStatements :: [Statement]
- aStatements = [True,True,True,True,True,True,True,True,True,False] -- 9 out of 10 A is truthful
- bStatements :: [Statement]
- bStatements = [True,True,True,True,True,True,True,True,False,False] -- 8 out of 10 B is truthful
- -- all possible combination of cards and statement choices
- allOptions :: [(Card, Statement, Statement)]
- allOptions = do
- card <- allcards -- for all cards
- a <- aStatements -- for all a's statements
- b <- bStatements -- for all b's statements
- return (card,a,b)
- --all the options where both said its a jack of clubs
- allSaidJC :: [(Card, Statement, Statement)]
- allSaidJC = filter (\(card,_,b) -> saidJC card b) $ filter (\(card,a,_) -> saidJC card a) allOptions
- --all the options where both claim jack of clubs and it actually is jack of clubs
- allIsJC :: [(Card, Statement, Statement)]
- allIsJC = filter (\(card,_,_) -> isJC card) allSaidJC
- --all the optiosn where both claim jack of clubs and it actuall not jack of clubs
- allIsNotJC :: [(Card, Statement, Statement)]
- allIsNotJC = filter (\(card,_,_) -> isnotJC card) allSaidJC
- someFunc = do
- putStrLn ("total card choices " ++ show (length allcards))
- putStrLn ("total combinations of card and truthfulness " ++ show (length allOptions))
- putStrLn ("options where claim is Jack of Clubs " ++ show (length allSaidJC))
- putStrLn ("options where claim is Jack of Clubs but it is not " ++ show (length allIsNotJC))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement