filmov
tv
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.
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).
Feel free to leave any questions.
Thanks for watching everyone!
~~~~~~~~~~~~~~~~~~~~~~~~
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).
Feel free to leave any questions.
Thanks for watching everyone!
~~~~~~~~~~~~~~~~~~~~~~~~
Комментарии