Created
January 4, 2015 11:50
-
-
Save skatenerd/185b384fa7f1fdceb848 to your computer and use it in GitHub Desktop.
scaffolding for http://realmode.com/
This file contains hidden or 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
import Data.Bool | |
import qualified Data.Map.Lazy as Map | |
data Encoding = Encoding (Bool, Bool, Bool) deriving (Eq, Ord) | |
data Assignment = Assignment { initial::Encoding, subsequent::[Encoding]} | |
data Letter = A | B | C | D deriving (Show, Enum, Eq, Ord) | |
type Solution = Map.Map Letter Assignment | |
checkPair solution pair = let (from, to) = pair | |
Just fromEncoding = Map.lookup from solution | |
Just toEncoding = Map.lookup to solution | |
hasPotentialTransition = any (initial fromEncoding <=) $ initial toEncoding : subsequent toEncoding | |
in hasPotentialTransition | |
check solution = | |
let allLetters = enumFrom A | |
pairs = [(x,y) | x <- allLetters, y <- allLetters] | |
in | |
all (checkPair solution) pairs | |
main = let | |
foo = Encoding (False, False, False) | |
bar = Encoding (True, True, True) | |
good = Map.fromList | |
[(A, Assignment {initial= Encoding (False, False, False), subsequent=[Encoding (True, True, True)]}), | |
(B, Assignment {initial= Encoding (False, False, True), subsequent=[Encoding (True, True, False)]}), | |
(C, Assignment {initial= Encoding (False, True, False), subsequent=[Encoding (True, False, True)]}), | |
(D, Assignment {initial= Encoding (True, False, False), subsequent=[Encoding (False, True, True)]})] | |
bad = Map.fromList | |
[(A, Assignment {initial= Encoding (False, False, False), subsequent=[]}), | |
(B, Assignment {initial= Encoding (False, False, True), subsequent=[Encoding (True, True, False)]}), | |
(C, Assignment {initial= Encoding (False, True, False), subsequent=[Encoding (True, False, True)]}), | |
(D, Assignment {initial= Encoding (True, False, False), subsequent=[Encoding (False, True, True)]})] | |
in do | |
print $ check good | |
print $ check bad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment