From 204b1f7fafb36d50515e41356462ed8a568dc57a Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Fri, 6 Dec 2019 00:00:07 -0800 Subject: [PATCH] Print the generated inputs again --- 2019/day5/intcode.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/2019/day5/intcode.rb b/2019/day5/intcode.rb index e53c07f..c0f583f 100644 --- a/2019/day5/intcode.rb +++ b/2019/day5/intcode.rb @@ -90,7 +90,7 @@ module Intcode r = @mem[@ip + 1] raise StandardError, "unexpected mode: #{mode[0]}" if mode[0] != 0 - @mem[r] = user_input.nil? ? input : user_input.call + @mem[r] = input(&user_input) @ip += 2 when 4 output = read(@ip + 1, mode[0]) @@ -131,17 +131,17 @@ module Intcode def input print 'input> ' - return default_input if @input.nil? + if block_given? + inp = yield + puts inp + return inp + end - inp = @input.call - puts inp - inp - end - - def default_input gets.to_i end + def default_input; end + def operation(cell) (cell % 100) end