Compare commits

...

2 Commits

Author SHA1 Message Date
5d02036f9e #1 Add README.md 2025-01-24 00:14:34 +01:00
6d2ac3675b Cleaning 2025-01-24 00:07:34 +01:00
2 changed files with 87 additions and 80 deletions

87
README.md Normal file
View File

@ -0,0 +1,87 @@
# Sudoku Funpark
Creating worlds most inefficient Sudoku solver, by trying every option, without any smart approach.
_(This was a learning project to get a better grasp of Golang. But more important; It was fun to do!.)_
## Goals
* Create the most inefficient Sudoku solver imaginable
* Be a learning experience for the Go programming language
I wrote [a blog post](https://blog.ligthert.net/posts/exploration-fun-and-process-cycles-of-sudoku/) about this.
## Usage
To use the sudoku solver, run the binary with all the parameters available:
```
Usage of ./sudoku-funpark:
-row1 string
1st row of the sudoku puzzle. (default "000000000")
-row2 string
2nd row of the sudoku puzzle. (default "000000000")
-row3 string
4rd row of the sudoku puzzle. (default "000000000")
-row4 string
4th row of the sudoku puzzle. (default "000000000")
-row5 string
5th row of the sudoku puzzle. (default "000000000")
-row6 string
6th row of the sudoku puzzle. (default "000000000")
-row7 string
7th row of the sudoku puzzle. (default "000000000")
-row8 string
8th row of the sudoku puzzle. (default "000000000")
-row9 string
9th row of the sudoku puzzle. (default "000000000")
```
Instead of using the 3x3 blocks with 3x3 digits, it uses horizontal rows from top to bottom.
## Example
To see the solver in action, run the tool with the following parameters.
For a short running (~15 seconds) example:
> $ ./sudoku-funpark -row1 769104802 -row2 154800060 -row3 832700154 -row4 600900328 -row5 045328670 -row6 328670945 -row7 597410280 -row8 006283090 -row9 200590006
For a long running (~1 hours 15 minutes) example:
> $ ./sudoku-funpark -row1 769104802 -row2 154800060 -row3 002700150 -row4 600900308 -row5 045328670 -row6 328670945 -row7 597410280 -row8 006283090 -row9 200590006
The outpot (of the short running parameters) will look something like this:
```
./sudoku-funpark -row1 769104802 -row2 154800060 -row3 832700154 -row4 600900328 -row5 045328670 -row6 328670945 -row7 597410280 -row8 006283090 -row9 200590006
2025/01/24 00:05:58 Loading blocks
2025/01/24 00:05:58 Loaded blocks (34.587221ms)
2025/01/24 00:05:58 Populating blocks
2025/01/24 00:05:58 Populated blocks (438.73054ms)
2025/01/24 00:05:58 Number of (potential) solutions: 26542080
2025/01/24 00:05:58 Validating solutions
2025/01/24 00:05:59 Processing: 6% (1729332/26542080); Rate (avg): 1729330/sec for 1.000003166s; Time left (est.): 14 seconds
2025/01/24 00:06:00 Processing: 13% (3461753/26542080); Rate (avg): 1732418/sec for 1.000002285s; Time left (est.): 13 seconds
2025/01/24 00:06:01 Processing: 19% (5228965/26542080); Rate (avg): 1767215/sec for 1.000019297s; Time left (est.): 12 seconds
2025/01/24 00:06:02 Processing: 26% (6996958/26542080); Rate (avg): 1767992/sec for 1.000200176s; Time left (est.): 11 seconds
2025/01/24 00:06:03 Processing: 33% (8767450/26542080); Rate (avg): 1770495/sec for 1.000016352s; Time left (est.): 10 seconds
2025/01/24 00:06:04 Processing: 39% (10576900/26542080); Rate (avg): 1809450/sec for 1.000014638s; Time left (est.): 8 seconds
2025/01/24 00:06:05 Processing: 46% (12400058/26542080); Rate (avg): 1823158/sec for 1.000352862s; Time left (est.): 7 seconds
2025/01/24 00:06:06 Processing: 53% (14185155/26542080); Rate (avg): 1785095/sec for 1.000254888s; Time left (est.): 6 seconds
2025/01/24 00:06:07 Processing: 60% (15968402/26542080); Rate (avg): 1783245/sec for 1.000002305s; Time left (est.): 5 seconds
2025/01/24 00:06:08 Processing: 66% (17655770/26542080); Rate (avg): 1687370/sec for 1.000068309s; Time left (est.): 5 seconds
2025/01/24 00:06:09 Processing: 73% (19442885/26542080); Rate (avg): 1787111/sec for 1.000006984s; Time left (est.): 3 seconds
2025/01/24 00:06:10 Processing: 79% (21183545/26542080); Rate (avg): 1740661/sec for 1.000002395s; Time left (est.): 3 seconds
2025/01/24 00:06:11 Processing: 86% (22998945/26542080); Rate (avg): 1815402/sec for 1.000113534s; Time left (est.): 1 second
2025/01/24 00:06:12 Processing: 90% (24109203/26542080); Rate (avg): 1110261/sec for 1.000312346s; Time left (est.): 2 seconds
2025/01/24 00:06:13 Processing: 100% (26542080/26542080); Rate (avg): 0/sec for 1.000117421s; Time left (est.): N/A
2025/01/24 00:06:13 Validated solutions (15.002654066s)
2025/01/24 00:06:13
Solution #1:
769154832
154832769
832769154
671945328
945328671
328671945
597416283
416283597
283597416
```
# Caveats
While this may very well solve all possible Sudoku puzzles (including the one [designed against brute force algorithms](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms)), the blanks in the puzzle, the harder it is, the more possible solutions there are, the more solutions it needs to parse, the longer it takes. As this is a computational heavy program, the more CPU you throw against it the faster it will solve issues.

View File

@ -1,80 +0,0 @@
Compat Matrix
1: 1 2 3 4 7
2: 1 2 3 5 8
3: 1 2 3 6 9
4: 1 4 5 6 7
5: 2 4 5 6 8
6: 3 4 5 6 9
7: 1 4 7 8 9
8: 2 5 7 8 9
9: 3 6 7 8 9
// counter: 123456789
// 1st Digit: 1 (49)
// 2nd Digit: 2 (50)
// 3rd Digit: 3 (51)
// 4th Digit: 4 (52)
// 5th Digit: 5 (53)
// 6th Digit: 6 (54)
// 7th Digit: 7 (55)
// 8th Digit: 8 (56)
// 9th Digit: 9 (57)
// 362880
// blocks := generate_blocks()
// fmt.Println(len(blocks))
// print_block(blocks[0])
// print_block(blocks[1])
// for i := range blocks {
// fmt.Println(blocks[i])
// }
row1 := "769104802"
row2 := "154800060"
row3 := "002700150"
row4 := "600900308"
row5 := "045328670"
row6 := "328670945"
row7 := "597410280"
row8 := "006283090"
row9 := "200590006"
row1 := "769154832"
row2 := "154832769"
row3 := "832769154"
row4 := "671945328"
row5 := "945328671"
row6 := "328671945"
row7 := "597416283"
row8 := "416284597"
row9 := "283597416"
// for rows1_index := range solver.row1s {
// for rows2_index := range solver.row2s {
// for rows3_index := range solver.row3s {
// for rows4_index := range solver.row4s {
// for rows5_index := range solver.row5s {
// for rows6_index := range solver.row6s {
// for rows7_index := range solver.row7s {
// for rows8_index := range solver.row8s {
// for rows9_index := range solver.row9s {
// go solver.routine_validator(rows1_index, rows2_index, rows3_index, rows4_index, rows5_index, rows6_index, rows7_index, rows8_index, rows9_index)
// // if solver.validate_combination(solver.row1s[rows1_index], solver.row2s[rows2_index], solver.row3s[rows3_index], solver.row4s[rows4_index], solver.row5s[rows5_index], solver.row6s[rows6_index], solver.row7s[rows7_index], solver.row8s[rows8_index], solver.row9s[rows9_index]) {
// // solver.solutions = append(solver.solutions, solver.render_combination(solver.row1s[rows1_index], solver.row2s[rows2_index], solver.row3s[rows3_index], solver.row4s[rows4_index], solver.row5s[rows5_index], solver.row6s[rows6_index], solver.row7s[rows7_index], solver.row8s[rows8_index], solver.row9s[rows9_index]))
// // }
// // solver.counter = solver.counter + 1
// // if solver.counter%1000000 == 0 {
// // percentage = (float32(solver.counter) / (float32(solver.iter) / 100))
// // fmt.Println("Processing:", percentage, "%; Procs:", runtime.NumGoroutine())
// // }
// }
// }
// }
// }
// }
// }
// }
// }
// }