From 99271d08830f06912fad7943a8456bddd5ae49a5 Mon Sep 17 00:00:00 2001 From: domi41 Date: Sat, 3 Jul 2021 22:47:04 +0200 Subject: [PATCH] fix: dynamically count the digits we're going to need for the score Solves two leftover `fixme`s to clean up things. --- majorityjudgment.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/majorityjudgment.go b/majorityjudgment.go index 0703ace..f086f0b 100644 --- a/majorityjudgment.go +++ b/majorityjudgment.go @@ -93,8 +93,9 @@ func (mj *MajorityJudgment) ComputeScore(tally *ProposalTally, favorContestation analysis := &ProposalAnalysis{} amountOfJudgments := tally.CountJudgments() - amountOfDigitsForGrade := 3 // fixme: compute - amountOfDigitsForAdhesionScore := 12 // fixme: compute + amountOfGrades := tally.CountAvailableGrades() + amountOfDigitsForGrade := countDigitsUint8(amountOfGrades) + amountOfDigitsForAdhesionScore := countDigitsUint64(amountOfJudgments * 2) mutatedTally := tally.Copy() for range tally.Tally { // loop once per grade @@ -110,3 +111,21 @@ func (mj *MajorityJudgment) ComputeScore(tally *ProposalTally, favorContestation return score, nil } + +func countDigitsUint8(i uint8) (count uint64) { + for i > 0 { + i = i / 10 // euclidean division + count++ + } + + return +} + +func countDigitsUint64(i uint64) (count uint64) { + for i > 0 { + i = i / 10 // Euclid wuz hear + count++ + } + + return +}