Showing results for 
Search instead for 
Did you mean: 

Help with Sudoku solver conversion from C

Go to solution

I also tried to randomize the insertion of the numbers in the array. Actually, it seems to work, but not always: as more the numbers in the input matrix are, the probability of generating a infinite loop increases... maybe it's the algorithm?


Also, the final result is only shown in the output matrix of, but in I can see only the output matrix of the first call of



0 Kudos
Message 11 of 20

You mean you are Replacing Array Subset.  Insert into Array is a completely different function that causes an array to grow.


I'm certain it would be the algorithm.  Solving Sudoku puzzles is pretty complicated.  It seems like it would require more code than you show here, but I can't see what is going on in the subVI's.


Would you really need recursion?  I think it would be a case of continually iterating over the puzzle, trying to solve more blocks as you discover more answers.

0 Kudos
Message 12 of 20

I think this would be much more difficult without recursion. The algorithm relies on going back in time if the chosen number doesn’t provide a solution.  


Since I couldn’t open the project, I created my own version of it, following the C code provided in the link. It does in fact work. I’ll post the code when I’m back at my computer. 

LabVIEW 2017
LabVIEW Programming
0 Kudos
Message 13 of 20

I visualize an automated solver that assumes all values are possible in each open box.  Then it eliminates possibilities because of values already known in the other boxes in the row, column, or 9-box.  You iterate over everything.  Once you see all choices have been eliminated but one, now you know the answer for that box and repeat the process.  Basically what I do when solving them.


No recursion.  No going back in time.  Just a lot of iteration.


Then there are some other rules to apply like if you have two numbers that can only exist in two boxes.  (So a 1-2 in one, and a 1-2 in another, then you eliminate all other possible numbers that could go into those same boxes.  That would be a little harder to code for.

Message 14 of 20

But what if a sudoku can have more than one solution?


Thanks aputman, I'll wait.

0 Kudos
Message 15 of 20

@Snorlite wrote:

But what if a sudoku can have more than one solution?


Thanks aputman, I'll wait.

Have you ever seen one with more than 1 solution?  It is certainly possible, but the puzzle makers are supposed to design it so it doesn't.

0 Kudos
Message 16 of 20
Accepted by Snorlite

I think the code would just display the first one that is found.  You would probably never know there was a second solution unless you changed the code to start from the end of the array rather than the beginning, or counted down from 9 to 1 instead of counting up from 1 to 9.  


It appears that you are very close with your code.  You still haven't removed the init matrix from the SolveSudoku VI.  It will not work until you do this.


See attached project.  

LabVIEW 2017
LabVIEW Programming
Message 17 of 20

Thank you very much, it does indeed work. I'll look at your code in detail.

0 Kudos
Message 18 of 20

Just a question, how did you create a reference to GridIn in

0 Kudos
Message 19 of 20

It's just a control reference with Array class selected.  You can create one in a couple of different ways.

  1. Right click the grid and Create -> Reference.  The right click this reference and create a control from it.  
  2. Insert a control reference from the refnum palette.  Right click -> Select Class -> Generic -> GObject -> Control -> Array.

LabVIEW 2017
LabVIEW Programming
Message 20 of 20