From d429c16a9e8ba6ad7f1da2cbcab09a0f43c26a94 Mon Sep 17 00:00:00 2001 From: ricola Date: Sat, 10 Jan 2026 19:00:26 -0600 Subject: [PATCH] Add tiebreak analyzer --- mj.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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