From 9153681df75211e892e0917e29981e478a5e014c Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Thu, 5 Dec 2019 23:14:53 -0800 Subject: [PATCH] Catch memory acces methods for debugging --- 2019/day5/intcode.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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