Day 18, part 1 - minor refactoring

This commit is contained in:
Jonathan Chan 2017-12-18 22:01:29 -08:00
parent c13fd64788
commit 87c7cf68c8
1 changed files with 3 additions and 6 deletions

9
18a.hs
View File

@ -21,12 +21,6 @@ getValue value registers = case value of
Number i -> i
c -> registers ! (getIndex c)
parseValue :: String -> Value
parseValue str =
case readMaybe str of
Just i -> Number i
Nothing -> Register $ head str
son :: Value -> State -> State
son freq (reg, pos, _, rec) =
(reg, pos + 1, getValue freq reg, rec)
@ -56,6 +50,9 @@ parseLine str =
"mod" -> app mod (parseValue $ head vs) (parseValue $ last vs)
"rcv" -> rcv $ parseValue $ head vs
"jgz" -> jgz (parseValue $ head vs) (parseValue $ last vs)
where parseValue s = case readMaybe s of
Just i -> Number i
Nothing -> Register $ head s
-- precondition: pos < length instructions
executeNextInstruction :: Seq Instruction -> State -> State