Day 9: I like error more than custom exceptions
This commit is contained in:
parent
345d628347
commit
f274db5fbe
|
@ -46,12 +46,6 @@ data TuringMachine =
|
||||||
}
|
}
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
data IntcodeExcept =
|
|
||||||
UnknownOpCodeException
|
|
||||||
deriving (Show)
|
|
||||||
|
|
||||||
instance Exception IntcodeExcept
|
|
||||||
|
|
||||||
tapePreprocess :: Vector Integer -> Vector Integer
|
tapePreprocess :: Vector Integer -> Vector Integer
|
||||||
tapePreprocess t = (V.++) t $ V.replicate 105 0
|
tapePreprocess t = (V.++) t $ V.replicate 105 0
|
||||||
|
|
||||||
|
@ -124,7 +118,7 @@ step tm =
|
||||||
else 0)
|
else 0)
|
||||||
"9" -> tmn {pointerOffset = pointerOffset tm + (params ! 0)}
|
"9" -> tmn {pointerOffset = pointerOffset tm + (params ! 0)}
|
||||||
"99" -> tm {state = Halt}
|
"99" -> tm {state = Halt}
|
||||||
_ -> throw UnknownOpCodeException
|
_ -> error "Illegal Opcode."
|
||||||
where
|
where
|
||||||
pNew = pointer tm + opLength (tape tm ! fromInteger (pointer tm))
|
pNew = pointer tm + opLength (tape tm ! fromInteger (pointer tm))
|
||||||
tmn = tm {pointer = pNew}
|
tmn = tm {pointer = pNew}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user