Usage:
counter = MultiCounter.new(3)
counter.add(12,2,10)
counter.add(9,9,4)
counter.values
# => [21, 11, 14]
class MultiCounter | |
def initialize(n) | |
@counters = [0]*n | |
end | |
def add(*values) | |
values.each_with_index do |v, i| | |
@counters[i] += v | |
end | |
end | |
def values | |
@counters | |
end | |
end |