diff --git a/mj.rb b/mj.rb index 03d0c37..0b96a34 100644 --- a/mj.rb +++ b/mj.rb @@ -65,6 +65,23 @@ class MajorityJudgment return MajorityJudgment.new(counta) <=> MajorityJudgment.new(countb) end + def break_tie(other) + rounds = [ ] + s = MajorityJudgment.new(self.count.dup) + o = MajorityJudgment.new(other.count.dup) + rounds << [s, o] + while s.mj == o.mj and not s.mj == 0 + new_s_count = s.count.dup + new_o_count = o.count.dup + new_s_count[s.mj] = new_s_count[s.mj] - 1 + new_o_count[o.mj] = new_o_count[o.mj] - 1 + s = MajorityJudgment.new(new_s_count) + o = MajorityJudgment.new(new_o_count) + rounds << [s, o] + end + return rounds + end + def to_s puts "#{@count}: {M=>#{self.mj}, P=>#{self.proponents}, O=>#{self.opponents}}" end