From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Sudoku Solver (Using Brute Force Algorithm) 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

1. Overview:
The objective is to fill a 9×9 grid so that each column, each row, and each of the nine 3×3 boxes (also called blocks or regions) contains the digits from 1 to 9 only one time each. The puzzle setter provides a partially completed grid.


2. Description:

 A brute force program would solve a puzzle by placing the digit "1" in the first cell and checking if it is allowed to be there. If there are no violations (checking row, column, and box constraints) then the algorithm advances to the next cell, and places a "1" in that cell. When checking for violations, it is discovered that the "1" is not allowed, so the value is advanced to a "2". If a cell is discovered where none of the 9 digits is allowed, then the algorithm leaves that cell blank and moves back to the previous cell. The value in that cell is then incremented by one. The algorithm is repeated until the allowed value in the 81st cell is discovered. The construction of 81 numbers is parsed to form the 9 x 9 solution matrix.

 

3. Requirements

  • LabVIEW 2012 (or compatible)

4. Steps to Implement or Execute Code

  1. Open Main (Brute Force).vi within Sudoku Solver (Brute Force) LabVIEW 2012 NI Verified.llb library
  2. Enter your puzzle in Problem
  3. Run the VI
  4. The program will resolve the sudoku

5. Additional Information or References

 VI Front Panel

 

Front Panel.JPG

 

**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.

Comments
francois-normandin
Member Member
Member
on

Works great. However, I'm disappointed we can't see the diagrams. I've come up with a sudoku solver a few years ago and would have loved to compare algorithms, and programmation styles.

GCentral ChampionCLA
fboteroh
Member
Member
on

Congratulations! great job! but I'm also disappointed. It's a pitty

BoF
moderator1983
Active Participant
Active Participant
on

Password is L@bV!EW


I am not allergic to Kudos, in fact I love Kudos.

 Make your LabVIEW experience more CONVENIENT.


elkag
Member
Member
on
Thank you for the password.