Catch memory acces methods for debugging
This commit is contained in:
parent
8ce1437b74
commit
9153681df7
1 changed files with 14 additions and 2 deletions
|
|
@ -14,16 +14,28 @@ module Intcode
|
||||||
Program.new parsed
|
Program.new parsed
|
||||||
end
|
end
|
||||||
|
|
||||||
class Memory < Array
|
class Memory
|
||||||
|
def initialize(cells)
|
||||||
|
@cells = cells
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
batch_size = 10
|
batch_size = 10
|
||||||
output = String.new
|
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
|
prefix = idx * batch_size
|
||||||
output << "#{prefix}: #{batch.join(' ')}\n"
|
output << "#{prefix}: #{batch.join(' ')}\n"
|
||||||
end
|
end
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def [](addr)
|
||||||
|
@cells[addr]
|
||||||
|
end
|
||||||
|
|
||||||
|
def []=(addr, val)
|
||||||
|
@cells[addr] = val
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue