X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-19.git;a=blobdiff_plain;f=intcode%2Fsrc%2FIntcode.hs;fp=intcode%2Fsrc%2FIntcode.hs;h=6d705332e985f3fc6e0a2d41dd4690d29f2c9e9b;hp=bdc4cb4adb84b244f4dba801641c7b6ba0972091;hb=5bfe9247189762b20f843032ecc8759a4324d210;hpb=6a1a537ac8f0d4fab44b806aa8986dce4aab8f9e diff --git a/intcode/src/Intcode.hs b/intcode/src/Intcode.hs index bdc4cb4..6d70533 100644 --- a/intcode/src/Intcode.hs +++ b/intcode/src/Intcode.hs @@ -58,11 +58,12 @@ runAll = do mem <- gets _memory ip <- gets _ip input <- ask iIndex <- gets _inputIndex + let opcode = (mem!ip) `mod` 100 let acutalInputLength = length input let requiredInputLength = iIndex + 1 - if (mem!ip == 99) + if (opcode == 99) then return Terminated - else if (mem!ip == 3 && requiredInputLength > acutalInputLength) + else if (opcode == 3 && requiredInputLength > acutalInputLength) then return Blocked else do runStep runAll @@ -88,6 +89,8 @@ fetchInput 3 modes = rb <- gets _rb inputIndex <- gets _inputIndex inputs <- ask + -- let ii = trace ("Input, index " ++ show inputIndex ++ " : available " ++ show (length inputs)) inputIndex + -- let mem' = iInsert (ip + 1) (modes!!0) rb (inputs!!ii) mem let mem' = iInsert (ip + 1) (modes!!0) rb (inputs!!inputIndex) mem modify (\m -> m {_inputIndex = inputIndex + 1, _memory = mem'}) fetchInput _ _ = return ()