diff --git a/2019/day5/intcode.rb b/2019/day5/intcode.rb index 4826b1f..9ee5aa8 100644 --- a/2019/day5/intcode.rb +++ b/2019/day5/intcode.rb @@ -14,16 +14,28 @@ module Intcode Program.new parsed end - class Memory < Array + class Memory + def initialize(cells) + @cells = cells + end + def to_s batch_size = 10 output = String.new - each_slice(batch_size).each_with_index do |batch, idx| + @cells.each_slice(batch_size).each_with_index do |batch, idx| prefix = idx * batch_size output << "#{prefix}: #{batch.join(' ')}\n" end output end + + def [](addr) + @cells[addr] + end + + def []=(addr, val) + @cells[addr] = val + end end class Program