Watch
1
0
Fork
You've already forked advent-of-code
0

Catch memory acces methods for debugging

This commit is contained in:
Jeremy Kaplan 2019-12-05 23:14:53 -08:00
commit 9153681df7

View file

@ -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