From 691c59462a73ad4db0a6dfddaca7772d1615dafd Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Mon, 5 Feb 2024 19:48:45 -0800 Subject: [PATCH] additional flags: -s to summarize, -r=false to suppress final result fun for seeing just how well it behaves on very large boards! it turns out printing the board is the slow part --- uckf.go | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/uckf.go b/uckf.go index c1fb792..446d362 100644 --- a/uckf.go +++ b/uckf.go @@ -9,7 +9,12 @@ import ( "math/rand" ) -var edgeSize = flag.Int("n", 15, "Cells per side") +var ( + edgeSize = flag.Int("n", 15, "Cells per side") + summarize = flag.Bool("s", false, "Summarize when iterating") + showResult = flag.Bool("r", true, "Show final result (default true)") +) + type scanState int const ( @@ -43,14 +48,34 @@ func main() { scream := uint64(0) for(isStillFucked(board, evals)) { if iterations >= scream { - dump(board, evals, fmt.Sprint("Iteration ", iterations)) + if (*summarize) { + emitSummary(evals, iterations) + } else { + dump(board, evals, fmt.Sprint("Iteration ", iterations)) + } scream = iterations << 1 } iterations++ fuckUp(board, evals) } - dump(board, evals, fmt.Sprintf("Not a single fuck (%d iterations)", iterations)) + if (*showResult) { + dump(board, evals, fmt.Sprintf("Not a single fuck (%d iterations)", iterations)) + } else { + emitSummary(evals, iterations) + } +} + +func emitSummary(evals [][]fuckness, iterations uint64) { + nFucked := uint64(0) + for _, row := range evals { + for _, e := range row { + if isFucked(e) { + nFucked++ + } + } + } + fmt.Printf("Iteration %d: %d fucked (%.2f%%)\n", iterations, nFucked, 100 * float64(nFucked)/(float64(*edgeSize * *edgeSize))) } func onBoard(i, j int) bool {