Example Code

Recursive Sudoku Solver in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This code allows the user to solve a 9x9 Sudoku.

 

Description

This VI iterates 9 times or less once the Sudoku is solve. First it checks if the Input Matrix "Input Sudoku" is Safe (If value is not possible in current board configuration, backtrack to previous board configuration). Then it uses Get Matrix Elements Function for extracting the Current Value of the Sudoku, if the number of column is equal to 8, the row is incremented and the VI is Recursively Call Itself else the column is incremented. If the result of the VI is true nothing happens else the value is replaced with the old one and exit the For Loop.

 

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Run VI

Additional Information or References

6108.png 

 

As this code makes use of the new recursion features in LabVIEW this code will only work with LabVIEW 2012 or newer.This program uses a recursive backtracking algorithm to solve the 9x9 grid.

Here are some example hard Sudokus that you can use to test. Simply drag and drop the images in LabVIEW 2012. These images were created using the new VI Snippet tool. The text-based Sudoku should be one line of 81 digits between 0-9. Zeros may also be replaced with dots (".").

 

**This document has been updated to meet the current required format for the NI Code Exchange.** 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.