From 53953cf47c77004d147d16eacac2b5bb71d9763c Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Sat, 25 Jan 2025 17:54:18 +0100 Subject: [PATCH] Fixing a leftover of #6, refactored to int64. --- solver/processing.go | 15 +++++++-------- solver/timers.go | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/solver/processing.go b/solver/processing.go index 2e6f1e4..0ede498 100644 --- a/solver/processing.go +++ b/solver/processing.go @@ -138,19 +138,18 @@ func (solver *Solver) tracker() { } timer_elapsed := time.Since(timer_start) - rate := int64(rate_diff) / int64(timer_elapsed.Seconds()) - solver.rates = append(solver.rates, rate) + solver.rates = append(solver.rates, rate_diff) rate_avg := solver.calc_avg() // Estimate when this is finished if rate_diff == 0 { est_fin = "N/A" } else { - est_fin = solver.secondsToHuman((int(solver.iter) - int(solver.counter)) / int(rate_avg)) + est_fin = solver.secondsToHuman((solver.iter - solver.counter) / rate_avg) } // Printing the progress - log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.Itoa(int(solver.counter)) + "/" + strconv.Itoa(int(solver.iter)) + "); Rate: " + strconv.Itoa(int(rate)) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin) + log.Println("Processing: " + strconv.Itoa(int(percentage)) + "% (" + strconv.Itoa(int(solver.counter)) + "/" + strconv.Itoa(int(solver.iter)) + "); Rate: " + strconv.FormatInt(rate_diff, 10) + "/sec for " + timer_elapsed.String() + "; Time left (est.): " + est_fin) // After we are done printing, exit this for-loop if percentage == 100 { @@ -170,6 +169,7 @@ func (solver *Solver) tracker() { // Resert the rate counter rate_start = solver.counter + // Sleep for a second time.Sleep(1 * time.Second) @@ -233,15 +233,14 @@ func (solver *Solver) validate_combination(row1 int, row2 int, row3 int, row4 in return retval } -func (solver *Solver) calc_avg() int { +func (solver *Solver) calc_avg() (avg int64) { var avg_sum int64 - var avg int for _, value := range solver.rates { avg_sum += value } - avg = int(avg_sum) / len(solver.rates) + avg = avg_sum / int64(len(solver.rates)) - return avg + return } diff --git a/solver/timers.go b/solver/timers.go index e454afc..ad35d7b 100644 --- a/solver/timers.go +++ b/solver/timers.go @@ -22,7 +22,7 @@ func (solver *Solver) plural(count int, singular string) (result string) { return } -func (solver *Solver) secondsToHuman(input int) (result string) { +func (solver *Solver) secondsToHuman(input int64) (result string) { years := math.Floor(float64(input) / 60 / 60 / 24 / 7 / 30 / 12) seconds := input % (60 * 60 * 24 * 7 * 30 * 12) months := math.Floor(float64(seconds) / 60 / 60 / 24 / 7 / 30)