projects
/
advent-of-code-19.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6a1a537
)
Fixed bug when checking opcode for blocking on input
author
Neil Smith
<neil.git@njae.me.uk>
Mon, 7 Dec 2020 11:34:10 +0000
(11:34 +0000)
committer
Neil Smith
<neil.git@njae.me.uk>
Mon, 7 Dec 2020 11:34:10 +0000
(11:34 +0000)
intcode/src/Intcode.hs
patch
|
blob
|
history
diff --git
a/intcode/src/Intcode.hs
b/intcode/src/Intcode.hs
index bdc4cb4adb84b244f4dba801641c7b6ba0972091..6d705332e985f3fc6e0a2d41dd4690d29f2c9e9b 100644
(file)
--- 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
ip <- gets _ip
input <- ask
iIndex <- gets _inputIndex
+ let opcode = (mem!ip) `mod` 100
let acutalInputLength = length input
let requiredInputLength = iIndex + 1
let acutalInputLength = length input
let requiredInputLength = iIndex + 1
- if (
mem!ip
== 99)
+ if (
opcode
== 99)
then return Terminated
then return Terminated
- else if (
mem!ip
== 3 && requiredInputLength > acutalInputLength)
+ else if (
opcode
== 3 && requiredInputLength > acutalInputLength)
then return Blocked
else do runStep
runAll
then return Blocked
else do runStep
runAll
@@
-88,6
+89,8
@@
fetchInput 3 modes =
rb <- gets _rb
inputIndex <- gets _inputIndex
inputs <- ask
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 ()
let mem' = iInsert (ip + 1) (modes!!0) rb (inputs!!inputIndex) mem
modify (\m -> m {_inputIndex = inputIndex + 1, _memory = mem'})
fetchInput _ _ = return ()