Recursion problem in sudoku solver

Tell us what’s happening:
I’m having some sort of problem involving recursion and scope with my sudoku solver. I’m using a recursive algorithm with backtracking to try and solve. Basically, it tries 1, and if that works it passes it to another instance of the same function which tries the next square. somehow, when there is an error and it backtracks, it puts a different number in, but the function it calls leaves the in between squares filled.
This error log likely explains things much better

  UnitTests
3  worked in space  [ 0, 1 ]
7  worked in space  [ 0, 3 ]
6  worked in space  [ 0, 4 ]
9  worked in space  [ 0, 6 ]
9  worked in space  [ 1, 0 ]
4  worked in space  [ 1, 1 ]
8  worked in space  [ 1, 4 ]
5  worked in space  [ 1, 7 ]
7  worked in space  [ 2, 0 ]
8  worked in space  [ 2, 2 ]
4  worked in space  [ 2, 3 ]
9  worked in space  [ 2, 5 ]
1  worked in space  [ 2, 6 ]
3  worked in space  [ 2, 7 ]
6  worked in space  [ 2, 8 ]
5  worked in space  [ 3, 0 ]
4  worked in space  [ 3, 2 ]
8  worked in space  [ 3, 3 ]
7  worked in space  [ 3, 5 ]
6  worked in space  [ 3, 6 ]
2  worked in space  [ 3, 7 ]
3  worked in space  [ 3, 8 ]
1  worked in space  [ 4, 1 ]
5  worked in space  [ 4, 3 ]
backtracking from  [ 4, 8 ]
backtracking from  [ 4, 3 ]
backtracking from  [ 4, 1 ]
backtracking from  [ 3, 8 ]
backtracking from  [ 3, 7 ]
backtracking from  [ 3, 6 ]
backtracking from  [ 3, 5 ]
backtracking from  [ 3, 3 ]
backtracking from  [ 3, 2 ]
6  worked in space  [ 3, 0 ]// here's where the issue is!!!!
1  worked in space  [ 5, 1 ]
5  worked in space  [ 5, 3 ]
4  worked in space  [ 5, 5 ]
6  worked in space  [ 5, 6 ]
8  worked in space  [ 5, 8 ]
3  worked in space  [ 6, 2 ]
2  worked in space  [ 6, 3 ]
9  worked in space  [ 6, 4 ]
5  worked in space  [ 6, 6 ]
6  worked in space  [ 6, 7 ]
5  worked in space  [ 7, 0 ]
8  worked in space  [ 7, 1 ]
7  worked in space  [ 7, 4 ]
3  worked in space  [ 7, 5 ]
4  worked in space  [ 7, 6 ]
2  worked in space  [ 7, 7 ]
5  worked in space  [ 8, 5 ]
backtracking from  [ 8, 8 ]
backtracking from  [ 8, 5 ]
backtracking from  [ 7, 7 ]
backtracking from  [ 7, 6 ]
backtracking from  [ 7, 5 ]
backtracking from  [ 7, 4 ]
backtracking from  [ 7, 1 ]
backtracking from  [ 7, 0 ]
backtracking from  [ 6, 7 ]
backtracking from  [ 6, 6 ]
backtracking from  [ 6, 4 ]
backtracking from  [ 6, 3 ]
backtracking from  [ 6, 2 ]
backtracking from  [ 5, 8 ]
8  worked in space  [ 5, 6 ]
no 0
    1) Solver returns the the expected solution for an incomplete puzzzle


  0 passing (71ms)
  1 failing

  1) UnitTests
       Solver returns the the expected solution for an incomplete puzzzle:

      AssertionError: expected '135762984946381257728459136699919999892936749317524899479998991991699999269149379' to equal '135762984946381257728459613694517832812936745357824196473298561581673429269145378'
      + expected - actual

      -135762984946381257728459136699919999892936749317524899479998991991699999269149379
      +135762984946381257728459613694517832812936745357824196473298561581673429269145378

I have disabled all but one mocha/chai test to more easily debug.

Your code so far
My code has a ton of comments, apologies in advance for the personal dev diary you’re about to open!
repl here, see line 202 for recursive function.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.

Challenge: Sudoku Solver

Link to the challenge:

So I think part of the problem is that I’m not removing the nine when it doesn’t work.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.