Skip to content

Commit

Permalink
Add BWAction
Browse files Browse the repository at this point in the history
This is inelegant, but slightly tidier than the current situation.
  • Loading branch information
nickdrozd committed Jul 29, 2020
1 parent f838020 commit 91d5705
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Rado.idr
Expand Up @@ -147,6 +147,10 @@ parseAction action = let actionIndex = strIndex action in do
state <- parseState $ actionIndex 2
Just (color, shift, state)

-- n is 2; needs to be changed for more colors
BWAction : Type
BWAction = Vect 2 Action

pairUp : List ty -> Maybe (List (Vect 2 ty))
pairUp [ ] = Just []
pairUp [_] = Nothing
Expand All @@ -164,7 +168,7 @@ inputWords : List String
inputWords = words rawInput

partial
ex : Maybe (List (Vect 2 Action))
ex : Maybe (List BWAction)
ex = pairUp $ mapMaybe parseAction inputWords

----------------------------------------
Expand All @@ -176,18 +180,18 @@ Cast State (Fin 4) where
cast Q4 = FS $ FS $ FS FZ
cast _ = FZ

Cast (Vect 2 Action) Instruction where
Cast BWAction Instruction where
cast [w, b] color =
case color of
W => w
B => b

makeProgram : (Vect 4 (Vect 2 Action)) -> Program
makeProgram : (Cast State $ Fin n) => (Vect n BWAction) -> Program
makeProgram actions state = cast $ index (cast state) actions

----------------------------------------

BB4Literal : Vect 4 (Vect 2 Action)
BB4Literal : Vect 4 BWAction
BB4Literal = [
[(B, R, Q2), (B, L, Q2)],
[(B, L, Q1), (W, L, Q3)],
Expand Down

0 comments on commit 91d5705

Please sign in to comment.