Compare commits

...

4 Commits

Author SHA1 Message Date
ff9c8315c1 Document flags (correctly). 2024-02-05 20:04:51 -08:00
691c59462a 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
2024-02-05 19:48:45 -08:00
cb63c009cc instructions 2024-02-05 19:16:41 -08:00
281cb218b3 Count iterations when done 2024-02-05 18:48:34 -08:00
2 changed files with 47 additions and 7 deletions

View File

@ -1,3 +1,20 @@
# uckf # uckf
A deeply unsatisfying word search. A deeply unsatisfying word search.
## Usage
1. [install the Go compiler](https://go.dev/dl/) if you don't have it yet
2. clone this repo (`git clone https://git.chromaticdragon.app/kistaro/uckf.git`)
3. `go run uckf.go`
4. you can use `-n` to specify a different grid size; for example, `go run uckf.go -n 100` will create a 100x100 unsatisfying word search
### Flags
* `-n <int>` -- use a grid with edges of length n
* `-s` -- summary mode; do not print intermediate grids, only summaries
* `-r=false` -- suppress final result (only print a summary for that)
## Notes
This algorithm converges much more quickly than I expected.

35
uckf.go
View File

@ -9,7 +9,12 @@ import (
"math/rand" "math/rand"
) )
var edgeSize = flag.Int("n", 8, "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 type scanState int
const ( const (
@ -39,20 +44,38 @@ func main() {
evals = append(evals, make([]fuckness, *edgeSize)) evals = append(evals, make([]fuckness, *edgeSize))
} }
dump(board, evals, "Starting position")
iterations := uint64(0) iterations := uint64(0)
scream := uint64(1) scream := uint64(0)
for(isStillFucked(board, evals)) { for(isStillFucked(board, evals)) {
if iterations >= scream { 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 scream = iterations << 1
} }
iterations++ iterations++
fuckUp(board, evals) fuckUp(board, evals)
} }
dump(board, evals, "Not a single fuck") 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 { func onBoard(i, j int) bool {