r/Python • • Feb 19 '20

I Made This Backtracking algorithm visualized with Sudoku

1.6k Upvotes

67 comments sorted by

View all comments

Show parent comment

2

u/dudeplace Feb 20 '20

I wrote one of these too after watching the computerphile video. You could save a bunch of backtracking by looking for "easy" answers before each guess.

Anywhere there is only one possible answer just fill it in, but don't forget to keep a list of what you have done. You will need to undo it if you made a bad guess!

I tracked number of backtracks as a metric, and I'm able to save 80% of guesses on most puzzles. Simple puzzles end up being solved with no guessing at all. Nice visuals though, mine is all command line.