icfp13/CircuitBase.hs
2010-06-23 13:48:17 +02:00

24 lines
688 B
Haskell

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
sdecode = do
(a, b, c) <- sdecode
return $ Chamber a (not b) c
sencode (Chamber a b c) = sencode (a, not b, c)
instance Encode Car where
sdecode = sdecode >>= (return . Car)
sencode (Car a) = sencode a
server_input = "01202101210201202"