Advertisement
Guest User

card prob

a guest
Mar 28th, 2021
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Lib
  2.     ( someFunc
  3.     ) where
  4.  
  5.  
  6. type Card = (Char,Char) -- ('J','C'),('K','S'),etc
  7.  
  8. type Statement = Bool -- True is truth, False is lied
  9.  
  10. allcards :: [Card]
  11. allcards = do
  12.             suit <- "HCDS"
  13.             card <- "JQK"
  14.             return (card,suit)
  15.  
  16. -- is Jack of Clubs
  17. isJC :: Card -> Bool
  18. isJC (card,suit) = card == 'J' && suit == 'C'
  19.  
  20. isnotJC :: Card -> Bool
  21. isnotJC x = not $ isJC x
  22.  
  23. saidJC :: Card -> Statement -> Bool
  24. saidJC card statement = (isJC card && statement) || (isnotJC card && not statement)
  25.  
  26. aStatements :: [Statement]
  27. aStatements = [True,True,True,True,True,True,True,True,True,False] -- 9 out of 10 A is truthful
  28.  
  29. bStatements :: [Statement]
  30. bStatements = [True,True,True,True,True,True,True,True,False,False] -- 8 out of 10 B is truthful
  31.  
  32. -- all possible combination of cards and statement choices
  33. allOptions :: [(Card, Statement, Statement)]
  34. allOptions = do
  35.             card <- allcards -- for all cards
  36.             a <- aStatements -- for all a's statements
  37.             b <- bStatements -- for all b's statements
  38.             return (card,a,b)
  39.  
  40. --all the options where both said its a jack of clubs
  41. allSaidJC :: [(Card, Statement, Statement)]
  42. allSaidJC = filter (\(card,_,b) -> saidJC card b) $ filter (\(card,a,_) -> saidJC card a) allOptions
  43.  
  44. --all the options where both claim jack of clubs and it actually is jack of clubs
  45. allIsJC :: [(Card, Statement, Statement)]
  46. allIsJC = filter (\(card,_,_) -> isJC card) allSaidJC
  47.  
  48. --all the optiosn where both claim jack of clubs and it actuall not jack of clubs
  49. allIsNotJC :: [(Card, Statement, Statement)]
  50. allIsNotJC = filter (\(card,_,_) -> isnotJC card) allSaidJC
  51.  
  52. someFunc = do
  53.             putStrLn ("total card choices " ++ show (length allcards))
  54.             putStrLn ("total combinations of card and truthfulness " ++ show (length allOptions))
  55.             putStrLn ("options where claim is Jack of Clubs " ++ show (length allSaidJC))
  56.             putStrLn ("options where claim is Jack of Clubs but it is not " ++ show (length allIsNotJC))
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement