Skip to content
Advertisement

How to stop Recursion and return answer?

This is a sudoku solver function and I have 2 questions:

JavaScript
  1. Why 2nd print print the original sudoku?

    JavaScript
  2. How can I get the sudoku solution (not print it), because I want to reuse the solution. (I have tried using return sudoku but get None)

Thanks:)

Advertisement

Answer

Maybe it is not elegant but I use global list all_solutions and append duplicated solution

JavaScript

It works for your example. But I still not sure if your code is correct.


JavaScript

The same using return instead of global variable.

Because solve() returns list of solutions so it has to also return [solution] as a list.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement