From 62da3effc4bd8a153ae9fa4493df02b2f379553b Mon Sep 17 00:00:00 2001 From: Corey Ogburn Date: Tue, 29 Mar 2022 12:51:33 -0600 Subject: [PATCH] Histogram fix When printing the histogram of victories by number of guesses it took, the length of the count is now taken into consideration so all the counts can be padded so the bars still line up. --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b64d1c4..df74a11 100644 --- a/main.go +++ b/main.go @@ -567,18 +567,28 @@ func (gs *GameStats) print(win *bool) { hist := make([]float64, TotalGuesses) max := float64(-1) + winPadding := 0 + for i := 0; i < TotalGuesses; i++ { hist[i] = float64(wins[i]) / float64(totalWins) if max < hist[i] { max = hist[i] } + + winWord := strconv.Itoa(wins[i]) + + if len(winWord) > winPadding { + winPadding = len(winWord) + } } mult := MaxHistogramBarLength / max // histogram for i := 0; i < TotalGuesses; i++ { - fmt.Printf("%d: %d %s\n", i+1, wins[i], strings.Repeat("█", int(math.Min(MaxHistogramBarLength, hist[i]*mult)))) + count := strconv.Itoa(wins[i]) + count = strings.Repeat(" ", winPadding-len(count)) + count + fmt.Printf("%d: %s %s\n", i+1, count, strings.Repeat("█", int(math.Min(MaxHistogramBarLength, hist[i]*mult)))) } if gs.ExperimentalEmojiSupport && win != nil {