I made a program that:
- Generates (possibly) wrong sudoku solutions.
- Checks if a solution is correct, and prints it if it is.
I tested it and it detects valid and invalid solutions correctly.
My problem is with generating a correct solution.
When telling the program to generate a new, random solution, until it finds a valid one, it just keeps running.
The way I generate the attempted 'solutions' is by making a list of 9 lists of 9 numbers each, each list being the numbers 1-9 mixed up, like so:
SUDOKU_ATTEMPT = [[8, 9, 6, 3, 7, 4, 2, 5, 1],
[6, 3, 4, 8, 1, 9, 7, 2, 5],
[1, 2, 5, 6, 8, 4, 7, 3, 9],
[1, 2, 9, 4, 3, 7, 8, 5, 6],
[6, 4, 9, 2, 3, 1, 7, 8, 5],
[3, 1, 8, 2, 7, 4, 9, 5, 6],
[3, 7, 2, 8, 4, 9, 5, 6, 1],
[7, 2, 1, 6, 4, 5, 3, 8, 9],
[2, 7, 8, 9, 4, 5, 1, 3, 6]]
As you can see, it's a given that rows will be correct. But not columns, nor 3x3 boxes.
I can provide the full code (should I?).
As mentioned, when checking a valid solution it detects it, and same for invalid ones.
I get no errors.
Posts I checked:
- Random sudoku generation (but it's C - I know python).
- Recursive solution to Sudoku generator (but it's Java - I know python).
- Generating minimal/irreducible Sudokus (not my question).
- Java sudoku generator not working correctly (Java, and it's not my problem).
- Generation of sudoku questions (not my question).
- Sudoku generator loop (Java, and not my question).
- Sudoku generation speed (Java - I know python)
- Sudoku Generator (Not my question, but seems not to have my problem. I used a very different approach (I think), so I couldn't figure out how to apply whatever was done the right way there, that I got wrong).
Aucun commentaire:
Enregistrer un commentaire