Skip to content

Instantly share code, notes, and snippets.

@nandor
Created January 19, 2014 14:03
Show Gist options
  • Save nandor/8505422 to your computer and use it in GitHub Desktop.
Save nandor/8505422 to your computer and use it in GitHub Desktop.
Boolean expression checker
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