parent
b177b0daa5
commit
84bd9e7c08
|
@ -4,6 +4,7 @@ module Intcode
|
||||||
, step
|
, step
|
||||||
, tapePreprocess
|
, tapePreprocess
|
||||||
, TMAction(Continue, Output, Halt)
|
, TMAction(Continue, Output, Halt)
|
||||||
|
, execSteps
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.DeepSeq as DeepSeq
|
import Control.DeepSeq as DeepSeq
|
||||||
|
@ -138,3 +139,11 @@ step tm =
|
||||||
case m !! (length params - 1) of
|
case m !! (length params - 1) of
|
||||||
Relative -> V.last opvec + pointerOffset tm
|
Relative -> V.last opvec + pointerOffset tm
|
||||||
_ -> V.last opvec
|
_ -> V.last opvec
|
||||||
|
|
||||||
|
execSteps :: TuringMachine -> TuringMachine
|
||||||
|
execSteps tm =
|
||||||
|
case state tmNew of
|
||||||
|
Continue -> execSteps tmNew
|
||||||
|
_ -> tmNew
|
||||||
|
where
|
||||||
|
tmNew = step tm
|
||||||
|
|
|
@ -25,9 +25,4 @@ main = do
|
||||||
["Part 1: " ++ show a ++ ", Part 2: " ++ show b | a <- out1, b <- out2]
|
["Part 1: " ++ show a ++ ", Part 2: " ++ show b | a <- out1, b <- out2]
|
||||||
|
|
||||||
runIntcode :: TuringMachine -> TuringMachine
|
runIntcode :: TuringMachine -> TuringMachine
|
||||||
runIntcode tm =
|
runIntcode = execSteps
|
||||||
case state tmNew of
|
|
||||||
Continue -> runIntcode tmNew
|
|
||||||
_ -> tmNew
|
|
||||||
where
|
|
||||||
tmNew = step tm
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user