Created
January 19, 2014 14:03
-
-
Save nandor/8505422 to your computer and use it in GitHub Desktop.
Boolean expression checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Monad | |
table :: [ [ Bool ] ] | |
table | |
= sequence $ replicate 4 [False, True] | |
eval :: [ Bool ] -> [ Bool ] | |
eval [ d, q2, q1, q0 ] | |
= [ x || y || (q2 && ( d || not q1)) || (d && z) | |
, (d && q2) || p || w || (not d && x) | |
, y || (d && p) || (q2 && (z || x)) || (d && (w || z)) | |
] | |
where | |
x = q1 && q0 | |
y = not d && not q2 && q1 | |
z = not q0 && not q1 | |
w = q0 && q2 | |
p = not q0 && not q2 | |
main :: IO () | |
main = do | |
forM_ table $ \row -> do | |
putStrLn $ show row ++ " " ++ show (eval row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment