LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Sudoku solver conversion from C

Solved!
Go to solution

Hi, I would like to implement in LabView this solveSudoku function written in C that makes use of recursion, but I can't manage to make it work.

 

 

Immagine.png

d.pngImmagine.png

 

The full project is in the attachment. The VI in which I have trouble is called solveSudoku.

 

Thanks for the help.

0 Kudos
Message 1 of 20
(3,220 Views)

If you need help, then help us help you by telling us in what way your code is not working.

0 Kudos
Message 2 of 20
(3,207 Views)

Posting by phone, only looking at your picture: shouldn't the 2D array be in a shift register?

 

0 Kudos
Message 3 of 20
(3,188 Views)

The program seems to continue to try to insert the number 1 in row 0 column 1, after having inserted it in row 0 column 0.

 

Yeah, maybe I should have set the shift registers, but the problem still persists.

0 Kudos
Message 4 of 20
(3,156 Views)

Unfortunately I can't open the project. Are the pictures showing the SolveSudoku VI? If so, you don't want to init the matrix on every call of the solver.  That should be done in your main VI. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 20
(3,131 Views)

A few other questions and quality-of-life comments...

Did you set the solver to be re-entrant?  If you don't, your shift register values are overwritten because you'll be calling the same instance of the VI.  You need a separate instance of SolveSudoku.vi each time it is called.

Why use an outer while loop when a for loop is easier to understand in the context?

There is a +1 primitive for incrementing a value by 1.

Inside the helper functions, create a gridOut terminal so that you hide those wire branches. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 6 of 20
(3,114 Views)

Why is the output matrix not wired to anything?

0 Kudos
Message 7 of 20
(3,099 Views)

I also notice you have a flaw in your interpretation of the algorithm.  If an insert is not possible, you should not call the solver.  There needs to be a break there so you can advance to the next number.  

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 8 of 20
(3,093 Views)

Yes, they are SolveSudoku VI screenshots.

 

Yes, I have set it to be re-entrant.

 

@altenbach if you're talking about the last screenshot, the output matrix wire is the one inside the case selector (It's just partially hidden by the selector border, sorry).

 

Btw, yeah, I found the logic problem too: I had to recursively call the VI only after a successful insertion.

 

Thanks for the tips.

0 Kudos
Message 9 of 20
(3,089 Views)
@aputman wrote:

Unfortunately I can't open the project. Are the pictures showing the SolveSudoku VI? If so, you don't want to init the matrix on every call of the solver.  That should be done in your main VI. 

I downloaded Sudoku.zip ‏225 KB and I can run the main.vi -

after a few seconds it throws the error 0x5F9 - too many recursive calls, because of "solvesudoku.vi"

 

You do call solvesudoku.vi within solvesudoku.vi - I think there's an easier way to do,

what you are trying to achieve.

 

When I delete the instance of "solvesudoku.vi" within solvesudoku.vi, run the .vi, I get this:

 0.PNG

 

 

When I use a Shift Register instead of the Tunnel, run the .vi, I get this:

(0_solveSudoku_MOD.vi does recursive-ly calculates the first row correctly, according to this source)

 

 1_with-shift-register.PNG

 

Think of Recursion in terms of Shift Registers, not in VI Calls !

 

edit: looks like you managed to do it with recursively calling the solvesudoku.vi -

would you show us your modification(s)?

 

 

0 Kudos
Message 10 of 20
(3,084 Views)