Name of Allah, Most Gracious, Most Merciful

Similar documents
Backtracking. See Section 7.7 p of Weiss


Submit your answers to these questions to the Curator under Quizzes as HW08 by the posted due date and time. No late submissions will be accepted.

CSE 143 Lecture 18. More Recursive Backtracking. slides created by Marty Stepp

Fundamentals, Design, and Implementation, 9/e Copyright 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e by David M.

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

The University of Nottingham

Recursion. move(64, 1, 2, 3);

Graphs. Directed graphs. Readings: Section 28

1. Answer as shown or -2 unless question allows partial credit. No points off for differences in spacing, capitalization, commas, and braces

Graphs. Readings: Section 28. CS 135 Fall : Graphs 1

Quadratic: the time that it takes to sort an array is proportional to the. square of the number of elements.

C:\Temp\Templates. Download This PDF From The Web Site

Chapter 6: Arrays. Starting Out with Games and Graphics in C++ Second Edition. by Tony Gaddis

C/C++ Programming Lecture 18 Name:

Lecture 6: Recursion RECURSION

CSE 142 Su01 Final Exam Sample Solution page 1 of 7

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

Dr. D. M. Akbar Hussain DE5 Department of Electronic Systems

CMSC132, Practice Questions

Functional Programming

That means circular linked list is similar to the single linked list except that the last node points to the first node in the list.

EXAM Computer Science 1 Part 1

CSCI 135 Software Design and Analysis, C++ Homework 8 Solution

ECE 250 Algorithms and Data Structures

Lecture 24 Notes Search in Graphs

This class simulates the Sudoku board. Its important methods are setcell, dorow, docolumn and doblock.

Solutions to Chapter 8

Constraint Satisfaction Problems (CSPs)

CS 206 Introduction to Computer Science II

Abstract Data Type: Stack

Ling/CSE 472: Introduction to Computational Linguistics. 5/4/17 Parsing

MTH 307/417/515 Final Exam Solutions

Binary Trees, Constraint Satisfaction Problems, and Depth First Search with Backtracking

Boolean Satisfiability: The Central Problem of Computation

Practice Problems for the Final

Recursion. James Brucker

Symmetry Detection and Exploitation in Constraint Programmi

SCJ2013 Data Structure & Algorithms. Bubble Sort. Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi

CMU-Q Lecture 7: Searching in solution space Constraint Satisfaction Problems (CSPs) Teacher: Gianni A. Di Caro

Building Java Programs. read: 12.5 Recursive backtracking

DIT411/TIN175, Artificial Intelligence. Peter Ljunglöf. 30 January, 2018

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

CSE 143. Linked Lists. Linked Lists. Manipulating Nodes (1) Creating Nodes. Manipulating Nodes (3) Manipulating Nodes (2) CSE 143 1

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08013 INFORMATICS 1 - FUNCTIONAL PROGRAMMING

2. List Implementations (a) Class Templates (b) Contiguous (c) Simply Linked (d) Simply Linked with Position Pointer (e) Doubly Linked

N N Sudoku Solver. Sequential and Parallel Computing

CS106B Handout #20 Winter February 4, Section Handout #4

Chapter 5: Recursion

Foundation Exam - Sample Problems for New Topics

Lecture Notes on Tries

Fun facts about recursion

Homework 4: due by 11:59pm on Wednesday, April 2, 2014 (Total: 100 points)

CS 314 Exam 2 Spring

Lecture 13: Two- Dimensional Arrays

Sudoku-4: Logical Structure

Lecture 24 Search in Graphs

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Depth-wise Hashing with Deep Hashing Structures. A two dimensional representation of a Deep Table

Lecture 8 Backtracking

Graphs. The ultimate data structure. graphs 1

Computer Science 136 Spring 2004 Professor Bruce. Final Examination May 19, 2004

CS61B Lecture #35. [The Lecture #32 notes covered lectures #33 and #34.] Today: Enumerated types, backtracking searches, game trees.

CS 1110 Final, December 17th, Question Points Score Total: 100

CMPSCI 187: Programming With Data Structures. Lecture #15: Thinking Recursively David Mix Barrington 10 October 2012

Types of files Command line arguments File input and output functions Binary files Random access

CSCI 2132 Software Development. Lecture 18: Functions

NET/JRF-COMPUTER SCIENCE & APPLICATIONS. Time: 01 : 00 Hour Date : M.M. : 50

2 2

Problem solving paradigms

COMPUTER SCIENCE. Paper 1

n Group of statements that are executed repeatedly while some condition remains true

Constraint (Logic) Programming

Topic 7: Algebraic Data Types

Part I: Short Answer (12 questions, 65 points total)

Instructions for Crossword Assignment CS130

Important Questions for Viva CPU

Announcements. CS 188: Artificial Intelligence Spring Today. Example: Map-Coloring. Example: Cryptarithmetic.

9691 COMPUTING. 9691/23 Paper 2 (Written Paper), maximum raw mark 75

Binary Trees. For example: Jargon: General Binary Trees. root node. level: internal node. edge. leaf node. Data Structures & File Management

Binary Tree Node Relationships. Binary Trees. Quick Application: Expression Trees. Traversals

CSC 126 FINAL EXAMINATION FINAL Spring 2012 B. Name (last, First) Instructor. Total Possible. Received

CS100M November 30, 2000

C++ - Lesson 2 This is a function prototype. a' is a function that takes an integer array argument and returns an integer pointer.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

Facebook. / \ / \ / \ Accenture Nintendo

Array. Prepared By - Rifat Shahriyar

L. S. Tang Department of Mathematics and Computer Science Western New England College Springfield, MA 01119

Homework 7: Sudoku. Preliminaries. Overview

CSE143 Notes for Monday, 7/06/15

Artificial Intelligence Constraint Satisfaction Problems

Building on the foundation. Now that we know a little about cout cin math operators boolean operators making decisions using if statements

CS32 Discussion Sec.on 1B Week 2. TA: Zhou Ren

Fundamental problem in computing science. putting a collection of items in order. Often used as part of another algorithm

Senet. Language Reference Manual. 26 th October Lilia Nikolova Maxim Sigalov Dhruvkumar Motwani Srihari Sridhar Richard Muñoz

Operators. Java operators are classified into three categories:

Exam 1 - (20 points)

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Objectives. Introduce static keyword examine syntax describe common uses

Transcription:

Name of Allah, Most Gracious, Most Merciful E-Mail: Hossein Fereidooni It was the best motivation for writing this article. 1

Hossein Fereidooni Solving Sudoku Using Informed Search Algorithms 2

Introduction In computer systems and in the third millennium, The speed is very important. Therefore, the algorithm attempts to design systems that will increase efficiency and The speed. In this important role in the computer games are entertaining people. The design of this game most of the algorithms used in artificial intelligence and the The speed mutual accountability between users and systems is important. Sudoku is one of the game now has its particular fans. This game simply because of the repeated failure to produce high numbers of permutations and variations in the size of the place is special. As an integral part of these games have been in news papers and journals. Many algorithms have been developed for the production of Othello and Backtracking recursive types that can be pointed and informed search, and more. Implement these algorithms, each has its limits. Program presented in this paper is to incomplete a Sudoku with a lack of resolve in the input table and provide a unique solution. The output of this program is one-hundredth The speed milliseconds. This time, the system varies with different structures. But total code and provided solutions to the competitive and has good The speed. Examples of solutions implemented in different times and this is visible. It speeds up the code using the search methods like binary search can be improved. Aim This article has tried using an array of three-dimensional array of values to help the candidate to be kept informed by the corresponding table, complete with its original element be in place. Original Sudoku solving the following three conditions: 1) The value of each column is unique. 2) The value of each row is unique. 3) the amount per square N * N is a unique internal. Note: The uniqueness of the meaning of Sudoku irregular, but between one and N is nonrepetitive. ( In this code, the full two-dimensional array of N = 3, and Table 81 has been assumed). Each search is evaluated. Using this technique ensures the uniqueness of each table. Informed by what? The use of algorithms for solving various problems to solve every problem is the hardest part. The algorithms informed use of different solutions to one of the best options for solving problems with limited visibility and space is finite. Provided that the appropriate selection method can have instant access to your choice. Sudoku short finite set of numbers is repeated with a combination of the above conditions are in place. To this 3

end the two-dimensional array can be used for display space. Due to the unique numbers to this point will be replaced Space needed in the algorithm is considerable space And even arrays with N = 4,5, 6 to easily use this method. Recommended to solve the N side of the table with an infinite desire to be avoided. Because there will be enough space for the auxiliary array. This algorithm is derived from the same characteristic The speed. Inappropriate and unnecessary to repeat it in other programs and remove the The speed increases. informed search algorithms is presented in the chart below: Chart informed search algorithms 4

Code Analysis: It is composed of two layers: 1) Presentation Layer 2) Business Layer Presentation layer in the array and to receive constructive input in the Business Class Sudoku sends. This code will see the two classes. It is a two-dimensional array for storing the operating table and uses it on. Square value of the array's internal default is 3. The amount varies for different size tables. Also, an internal array of type Bool is used for storing the unique array. These variables are defined as global-level class with a different method of operation can be performed on these values. The following code is inserted Sudoku incomplete. Zero points in the input string represented in the table is empty. Sudoku for the complete accuracy of the output is presented By comparing these values to the user able to see the correct answer. This code is part of a class of Sudoku and the Fill method to send the missing states. This method is used to fill the array of internal Sudoku. Presentation layer code Sudoku SUdok = new Sudoku(); string[] SolvedSudoku = new string[81]; string temp1 = "219876435843591276765243891394157628127368954658429317482735169536914782971682543"; for (int i = 0; i < 81; i++) SolvedSudoku[i] = Convert.ToString(temp1[i]); SUdok.Fill(SolvedSudoku); lblcompletesudoko.text = SUdok.Show(); for (int i = 0; i < 81; i++) SolvedSudoku[i] = "0"; //entry sudoku // value 0 is null in entry sudoku string temp = "219876435803591276065243891394150628127368954658429307482735169536914702970682543"; for (int i = 0; i < 81; i++) SolvedSudoku[i] = Convert.ToString(temp[i]); SUdok.Fill(SolvedSudoku); 5

These variables have been created and initialized by the constructor of the variables are defined. Business Layer Code public class Sudoku //N*N Board int N = 3; //Main Board int[,] board = new int[9, 9]; //this arry used by methods that Checked the value is unique in row and col and inner cubes bool[] checkvalue = new bool[10]; //constructore public Sudoku() //Fill main Array board by 0 value for (int i = 0; i <= (N * N)-1; i++) board[i, j] = 0; //fill check array with default value for (int i = 0; i <= 9; i++) checkvalue[i] = true; This method of access to the i, j element two-dimensional array that provides the main table. // set value in main board //i, j position of element array //value i,j element array public void setsquare(int i, int j, int value) board[i, j] = value; //get value for acrross row and col value // i = row // j = col public int getsquare(int i, int j) return board[i, j]; This method of display two-dimensional table with the three main characters + and - and are the numbers. Character - a row of the intersection of the column and row and column is used. 6

//this method Add " " and "-" and "+" to show result in output.%3 put " " in each ternary in row. // public string Show() string Temp = string.empty; for (int i = 0; i <= (N * N)-1; i++) //this if dont allow to loop for input " " at first if (j % 3 == 0 && j!= 0) Temp += " "; //this if check for put "+" in out put at Confluence row and col in each cubes number if (i % 3 == 0 && i!= 0 && j == 0) for (int k = 0; k < 18; k++) if (k % 6 == 0 && k!= 0) Temp += "+"; Temp += "---"; Temp += "\r\n"; // insert dot Instead of zero if (board[i, j] == 0) Temp += ". "; Temp += " " + board[i, j] + " "; Temp += "\r\n"; return Temp; As above-mentioned method for inserting FILL incomplete array of input values used in the original array. FancyFill method for array values as input in excess of incomplete Tues. characters + and - and are used for display. //fill main board by input string array public void Fill(string[] lines) int k = 0; 7

for (int i = 0; i <= (N * N)-1; i++) board[i, j] = int.parse(lines[k]); k++; //fill board by input string array and delete any + - in input string // this method for check two condition use peterson solution public void FancyFill(string[] lines) for (int i = 0; i <= (N * N)-1; i++) board[i, j] = 0; int k = 0; bool flag = true; for (int i = 0; i <= (N * N)-1; i++) flag = true; //peterson solution for (int l = k; l < lines.length && flag; l++) if (char.isdigit(char.parse(lines[l]))) board[i, j] = int.parse(lines[l]); flag = false; if (char.parse(lines[l]) == '.') board[i, j] = 0; flag = false; k++; IsSolution() : Checks whether or not it is solving sudoku? For this purpose, uses four auxiliary functions. The performance of four methods as follows: 1) IsComplete(): This method is used for all array element. 2) isrowcheckunique() : This method is unique for all rows of the original array is used. 3) iscolcheckunique() : This unique method for all columns used in the original array. 4) iscubeunique() : This method is unique for each of the 3 3 cube is built. 8

The four were Sudoku solving method if the answer is True. // check sudoku is solved? if true return true public bool issolution() if (iscomplete() && isrowcheckunique() && iscolcheckunique() && iscubeunique()) return true; //check board array is complete by number? public bool iscomplete() for (int i = 0; i <= (N * N)-1; i++) if (!(board[i, j] <= 9 && board[i, j] >= 1)) return true; //values in rows is unique? use check value array for true or false public bool isrowcheckunique() for (int i = 0; i <= (N * N)-1; i++) // if (checkvalue[board[i,j]] == true) checkvalue[board[i,j]] = false; return true; 9

//values in columns is unique? use check value array for true or false public bool iscolcheckunique() for (int i = 0; i <= (N * N)-1; i++) if (checkvalue[board[i,j]] == true) checkvalue[board[i,j]] = false; return true; //this method check evry 3*3 is 1..9 value? //if is unique return true. public bool iscubeunique() #region iscubeunique //1,1 for (int i = 0; i <= 2; i++) for (int j = 0; j <= 2; j++) //1,2 for (int i = 0; i <= 2; i++) for (int j = 3; j <= 5; j++) 10

//1,3 for (int i = 0; i <= 2; i++) for (int j = 6; j <= 8; j++) //2,1 for (int i = 3; i <= 5; i++) for (int j = 0; j <= 2; j++) //2,2 11

for (int i = 3; i <= 5; i++) for (int j = 3; j <= 5; j++) //2,3 for (int i = 3; i <= 5; i++) for (int j = 6; j <= 8; j++) //3,1 for (int i = 6; i <= 8; i++) for (int j = 0; j <= 2; j++) 12

//3,2 for (int i = 6; i <= 8; i++) for (int j = 3; j <= 5; j++) //3,3, for (int i = 6; i <= 8; i++) for (int j = 6; j <= 8; j++) return true; #endregion Three-dimensional array InnerCandidateValue This array is used to hold element values for each candidate. Considering that the original 81 houses, each array must have some unique value in athree-dimensional array with the values and placed in the correct position is his. 13

//candidate value global list int[,,] InnerCandidateValue = new int[10, 10, 11]; FillcandidateValue(): This method is used to fill the array of candidates for conservative values. //inner candidate value fill public void FillcandidateValue() //fill candidate value in innner list for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) for (int k = 0; k < 11; k++) InnerCandidateValue[i, j, k] = k; solvedsudoku() : This method is used to solve Sudoku incomplete. This program is part of the method. In this method, the number of incomplete element main array of the array is a candidate. If the three conditions was the main Sudoku array of candidates for the correct amount is placed on the next blank. If the array of candidates to replace the new value should be checked again. Finally, the correct amount in the blank element and informed seek to solve Sudoku. //this method solve sudoku by Informed solution public void SolvedSudoku() FillcandidateValue(); //solve for (int i = 0; i <= (N * N) - 1; i++) for (int j = 0; j <= (N * N) - 1; j++) if (board[i, j] == 0) for (int l = 0; l <= 8; l++) board[i, j] = InnerCandidateValue[i, j, l+1]; if ((isonerowcheckuniqe(i) && isonecolcheckuniqe(j) && iscubeunique())) l = 10; Finally, the presentation layer, it will display the full amount. This is shown next to an empty array. Finally, by solving an array of programs is displayed. The function of each table 14

Issolution () to check and ensure the correctness of the program is placed. Also at the beginning and end time in milliseconds is displayed on the system until the problem is presented. OutPut.Text = SUdok.Show(); lblissolution.text = Convert.ToString(SUdok.isSolution()); SUdok.SolvedSudoku(); lblissolution2.text = Convert.ToString(SUdok.isSolution()); lbloutput2.text = SUdok.Show(); Time = string.empty; Time = DateTime.Now.Minute.ToString() + " " + DateTime.Now.Second.ToString() + " " + DateTime.Now.Millisecond.ToString(); lbltimeend.text += Time; Using The Code: To use the code to create a Windows Forms project and add to the Sudoku class. An input value of the class and put in the variable Temp. For example, with a truncated version of Sudoku has been placed in this variable. The output format is shown below: 15