Coding a Sudoku solver in Python using recursion/backtracking

Описание к видео Coding a Sudoku solver in Python using recursion/backtracking

Learn how to code a Sudoku puzzle solver in Python! In this tutorial, I explain how recursion/backtracking work in order to solve a Sudoku puzzle input.

Code: https://github.com/kying18/sudoku
- sudoku_empty.py: empty template with optional helper functions and comments in the code for the steps
- sudoku.py: my solution from the video!

In this video, I go over the steps necessary to use recursion to solve the input. Basically, the steps we need to follow are: determine where the next guess should go, place a guess between 1-9, then attempt to solve by recursively calling the mutating function. If the function solves the puzzle, then we are done. Otherwise, we reset our guess and guess another number.

At the end, we've literally tried every single combination of numbers on the board, through the backtracking process, so if we haven't reached a solution, then we know that our puzzle is unsolvable.

Of course, this is not a very "intelligent" solution in the sense that we have to try all the various combinations. There is probably a more optimized solution out there that can solve the problem in fewer steps. This is a good exercise to try! If you think your solution is good, you can make a pull request on github or just DM me your solution. I might include it in the github (with credits to you ofc).

Check out this wiki page for some more info about sudoku algorithms that are more intelligent than just backtracking: https://en.wikipedia.org/wiki/Sudoku_...

Feel free to leave any questions.

Please consider subscribing if you liked this video: https://www.youtube.com/c/ycubed?sub_...

Thanks for watching everyone!
~~~~~~~~~~~~~~~~~~~~~~~~
Follow me on Instagram:   / kylieyying  
Follow me on Twitter:   / kylieyying  
Check out my website: https://www.kylieying.com

Комментарии

Информация по комментариям в разработке