Move user input to run method
This commit is contained in:
parent
28d32820fc
commit
8ce1437b74
1 changed files with 2 additions and 6 deletions
|
|
@ -33,11 +33,7 @@ module Intcode
|
|||
@initial_state = mem
|
||||
end
|
||||
|
||||
def on_input(&block)
|
||||
@input = block
|
||||
end
|
||||
|
||||
def run
|
||||
def run(&user_input)
|
||||
@mem = Memory.new(@initial_state.clone)
|
||||
ip = 0
|
||||
loop do
|
||||
|
|
@ -68,7 +64,7 @@ module Intcode
|
|||
r1 = mem[ip + 1]
|
||||
raise StandardError, "unexpected mode: #{mode[0]}" if mode[0] != 0
|
||||
|
||||
mem[r1] = input
|
||||
mem[r1] = user_input.nil? ? input : user_input.call
|
||||
ip += 2
|
||||
when 4
|
||||
r1 = mem[ip + 1]
|
||||
|
|
|
|||
Loading…
Reference in a new issue