Fixes build; prettifies output
2 files changed, 27 insertions(+), 7 deletions(-)

M .build.yml
M main.go
M .build.yml +1 -1
@@ 6,7 6,7 @@ packages:
     - zip
     - curl
 sources:
-    - hg+https://hg.sr.ht/~ser/score-better-balance
+    - hg+https://hg.sr.ht/~ser/MARS
 secrets:
     - 45926939-38b0-4e7f-bfa5-1a5b5786a773
     - d7d86c19-5b94-4c65-bf07-b8b30f55bd63

          
M main.go +26 -6
@@ 54,7 54,9 @@ func main() {
 	if cycle {
 		printScoreDetails(w, lines, badVotes, ints, diffs, ttl)
 		// If there's a tie, then it's a hard tie
-		checkTie(lines[0], subtotal(ints), w)
+		if checkTie(lines[0], subtotal(ints), w) {
+			fmt.Println("Hard tie (no winner possible)")
+		}
 		return
 	}
 

          
@@ 103,6 105,22 @@ func subtotal(lines [][]int) []int {
 	return ttls
 }
 
+// subtotal sums up the columns, and returns a single row of the sums
+func countVoters(lines [][]int) []int {
+	if len(lines) < 1 {
+		return []int{}
+	}
+	ttls := make([]int, len(lines[0]))
+	for _, row := range lines {
+		for c, cell := range row {
+			if cell != 0 {
+				ttls[c]++
+			}
+		}
+	}
+	return ttls
+}
+
 // winner finds the column with the highest sum of values in a matrix,
 // and returns the index of the winning column as well as the calculated
 // score. the winner by score.

          
@@ 231,6 249,8 @@ func printScoreDetails(wc int, hlines, b
 	printWithCandidates("Summary of distributions", true, header, uniq(lines))
 	subttl := subtotal(ints)
 	printWithCandidates("Subtotals", false, header, subttl)
+	voters := countVoters(ints)
+	printWithCandidates("# voters", false, []string{}, voters)
 	subWc := max(subttl)
 	fmt.Printf("Winner by score: %s with %d\n", header[subWc], subttl[subWc])
 }

          
@@ 238,8 258,8 @@ func printScoreDetails(wc int, hlines, b
 func printAdjustDetails(wc int, hlines, badVotes [][]string, ints [][]int, diffs [][]int, ttl []int) {
 	header := hlines[0]
 	printWithCandidates("Summary of diffs", true, header, uniq(toString(diffs)))
-	printWithCandidates("Modifiers", false, header, subtotal(diffs))
-	printWithCandidates("Totals", false, header, ttl)
+	printWithCandidates("Modifiers", false, []string{}, subtotal(diffs))
+	printWithCandidates("Totals", false, []string{}, ttl)
 	fmt.Printf("Highest combined total: %s with %d\n", header[wc], ttl[wc])
 
 	if len(badVotes) > 0 {

          
@@ 314,6 334,9 @@ func toString(lines [][]int) [][]string 
 // the same way.
 func printWithCandidates(d string, count bool, cands []string, v interface{}) {
 	fmt.Println(d)
+	if len(cands) > 0 {
+		fmt.Printf(" \t%s\n", strings.Join(cands, "\t"))
+	}
 	switch a := v.(type) {
 	case [][]string:
 		if count {

          
@@ 321,7 344,6 @@ func printWithCandidates(d string, count
 				return a[i][0] > a[j][0]
 			})
 		}
-		fmt.Printf(" \t%s\n", strings.Join(cands, "\t"))
 		for _, r := range a {
 			if !count {
 				fmt.Printf(" \t")

          
@@ 334,7 356,6 @@ func printWithCandidates(d string, count
 				return a[i][0] > a[j][0]
 			})
 		}
-		fmt.Printf(" \t%s\n", strings.Join(cands, "\t"))
 		for _, r := range a {
 			if !count {
 				fmt.Printf(" \t")

          
@@ 350,7 371,6 @@ func printWithCandidates(d string, count
 				return a[i] > a[j]
 			})
 		}
-		fmt.Printf(" \t%s\n", strings.Join(cands, "\t"))
 		if !count {
 			fmt.Printf(" \t")
 		}