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 {