Add circuit build function
This commit is contained in:
parent
09e41db6b1
commit
ac5fb44cac
22
Circuit.hs
22
Circuit.hs
@ -5,6 +5,12 @@ import Data.List
|
||||
|
||||
type Nat = Int
|
||||
|
||||
-- IMPORANT functions:
|
||||
-- * build
|
||||
-- create a circuit for a desired fuel output
|
||||
-- example:
|
||||
-- build key
|
||||
|
||||
-- Circuit Syntax:
|
||||
-- <inPin>:[<gates>]:<outPin>
|
||||
-- each Pin is either "X" (circuit IN or OUT)
|
||||
@ -42,6 +48,22 @@ test0 = fact0_output == execcirc factory0
|
||||
-- known server input stream (from factory "X::X")
|
||||
input = readstream "01202101210201202"
|
||||
|
||||
block0 = 0:(init input)
|
||||
block1 = 1:(init input)
|
||||
block2 = 2:(init input)
|
||||
|
||||
-- basic blocks
|
||||
-- 0: 1R:2L1L0#X2L,2RX0#0R2R,0R1R0#0L1L:0L
|
||||
-- 1: 2L:2R1R0#2R1R,2L0R0#X0R,X0L0#1L0L:1L
|
||||
-- 2: 2R:2R1R0#2L1L,0R2L0#X0R,0LX0#1R0L:1L
|
||||
-- build circuit for needed output
|
||||
build s = let (p, pins) = step (-1) [] (reverse s) in Circuit p pins where
|
||||
step p gates [] = (p, gates)
|
||||
step p gates (x:xs) = let k = length gates in case x of
|
||||
0 -> step k (gates ++ [k+4,k+2,k+5,p,k+1,k+3]) xs
|
||||
1 -> step (k+2) (gates ++ [k+5,k+3,k+4,k+1,p,k]) xs
|
||||
2 -> step (k+2) (gates ++ [k+5,k+3,k+1,k+4,k,p]) xs
|
||||
|
||||
data Circuit = Circuit { outPin :: Int, inPins :: [Int] } deriving (Eq)
|
||||
|
||||
instance Show Circuit where
|
||||
|
Loading…
Reference in New Issue
Block a user