Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C Code: The program uses bit-masks to represent the possible states for each square of the Sudoku puzzle. As each square can be any

Using C Code:

image text in transcribedimage text in transcribed

The program uses bit-masks to represent the possible states for each square of the Sudoku puzzle. As each square can be any one of 9 numbers (1-9), we will use 9- bits (bits 0-8, where bit 0 is the least significant bit (L.SB)) to represent which of the numbers each square can be. For example, if the value stored for a square is 0x14F where bits 0,12,3.6, and 8 are set, then this square can be the values 1,2,3,4,7, and 9 and not the values 5,6, and 8. The key to solving Sudoku puzzles is eliminating possibilities of an unknown square until there is only one remaining possibility that must be the answer. We use two rules to eliminate possibilities: Rule 1: If we know the value for a given square (i.e., it is a "singleton" where there is only one possible for the value for the square), then no square in the same row,column, or 3*3 square can hold the same value. That means that we can remove that possibility from all of those squares. Rule 2: If there is only one square in a given row, column or 3*3 square that can hold a given value, then it must be the one that holds that value. All other possibilities can be eliminated from that square. These two rules are sufficient to solve all but the most difficult Sudoku puzzles There are two parts in this MP. In the first part, you will develop some helper methods necessary to get the code to work. In the second, you implement rule 2 The program uses bit-masks to represent the possible states for each square of the Sudoku puzzle. As each square can be any one of 9 numbers (1-9), we will use 9- bits (bits 0-8, where bit 0 is the least significant bit (L.SB)) to represent which of the numbers each square can be. For example, if the value stored for a square is 0x14F where bits 0,12,3.6, and 8 are set, then this square can be the values 1,2,3,4,7, and 9 and not the values 5,6, and 8. The key to solving Sudoku puzzles is eliminating possibilities of an unknown square until there is only one remaining possibility that must be the answer. We use two rules to eliminate possibilities: Rule 1: If we know the value for a given square (i.e., it is a "singleton" where there is only one possible for the value for the square), then no square in the same row,column, or 3*3 square can hold the same value. That means that we can remove that possibility from all of those squares. Rule 2: If there is only one square in a given row, column or 3*3 square that can hold a given value, then it must be the one that holds that value. All other possibilities can be eliminated from that square. These two rules are sufficient to solve all but the most difficult Sudoku puzzles There are two parts in this MP. In the first part, you will develop some helper methods necessary to get the code to work. In the second, you implement rule 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

Describe key customer feedback collection tools.

Answered: 1 week ago

Question

Know what customers expect from the firm when they complain.

Answered: 1 week ago

Question

Understand why customers complain.

Answered: 1 week ago