icfp13/CircuitBase.hs

24 lines
688 B
Haskell
Raw Normal View History

2010-06-23 10:50:41 +00:00
module CircuitBase (Circuit(..), Chamber(..), Car(..), server_input, circ_from_perm) where
import Encoding
data Circuit = Circuit { outPin :: Int, inPins :: [Int] } deriving (Eq, Show)
circ_from_perm (x:xs) = if (odd $ length xs) then error "Wrong pin count" else Circuit x xs
data Chamber = Chamber { upperPipe :: [Int], mainChamber :: Bool, lowerPipe :: [Int] }
data Car = Car { chambers :: [Chamber] }
instance Encode Chamber where
2010-06-23 11:48:17 +00:00
sdecode = do
(a, b, c) <- sdecode
return $ Chamber a (not b) c
2010-06-23 10:50:41 +00:00
sencode (Chamber a b c) = sencode (a, not b, c)
instance Encode Car where
2010-06-23 11:48:17 +00:00
sdecode = sdecode >>= (return . Car)
2010-06-23 10:50:41 +00:00
sencode (Car a) = sencode a
server_input = "01202101210201202"