r/learnpython • u/QueasyCarBoy • 20h ago
Does anyone play high level sudoku?
Hi,
I'm trying to make a very advanced sudoku player in python.
However, it generates sudokus far too slowly. Can someone help me? (I'll only share source code once someone says yes)
EDIT: found solution, deleting in a week
6
u/schoolmonky 16h ago
Why would you refuse to show your code until someone agrees to help? That just slows the whole process down. If you show your code upfront, someone can jump right in with giving advice.
1
2
u/LayotFctor 19h ago
How slow are we talking here?
1
u/QueasyCarBoy 10h ago
like "no visible progress in 30 entire seconds" slow.
1
u/LayotFctor 6h ago
Since sudoku states cannot be statically knowable to be solvable, you always need to run the solver to verify. Perhaps you forgot to discard an invalid board state and got stuck in an infinite loop?
Otherwise it's probably your algorithm, such as forgetting to check for the cell with the lowest number of options and creating an exponential complexity.
1
1
u/Kevdog824_ 16h ago
Can you describe the steps you do to generate boards and verify solutions? We might be able to point out an issue with your approach
1
u/QueasyCarBoy 10h ago
sure, here is my best attempt to share my entire program: https://drive.google.com/file/d/1lURfk2XK25FNAq7oD_eU3TcQK4Mtz0H9/view?usp=sharing
1
u/Kevdog824_ 8h ago
I saw your comment below:
like "no visible progress in 30 entire seconds" slow.
The search runs on Tkinter’s main thread, so the GUI is blocked and can’t show progress or respond until generation finishes. That explains the "no visible progress", but not necessarily why generation takes so long. Which difficulty were you generating, and did this happen at startup or after clicking “New game”? That would help me reproduce the slowdown and investigate it.
0
18h ago
[deleted]
1
u/QueasyCarBoy 10h ago
yeah that was what i was thinking. I was trying to make a program to play and generate really difficult sudokus (up to AIC difficulty), but it failed to generate anything past locked candidates difficulty.
And for up to naked singles, it just gave a sudoku with one missing number.
12
u/SCD_minecraft 19h ago
Don't ask to ask, just ask and post source code
Sudoku is slow to create and solve, as it is basically graph coloring problem which has no fast known solutions