Sudoku Solver Version: 2.5 Due Date: April 5 th 2013

Similar documents
UN DOS TREZ Sudoku Competition. Puzzle Booklet for Preliminary Round. 19-Feb :45PM 75 minutes

Investigation of Algorithmic Solutions of Sudoku Puzzles

INTRODUCTION TO COMPUTER SCIENCE I PROJECT 6 Sudoku! Revision 2 [2010-May-04] 1

8. You Won t Want To Play Sudoku Again

ENGR170 Assignment Problem Solving with Recursion Dr Michael M. Marefat

SUDOKU X. Samples Document. by Andrew Stuart. Moderate

On the Combination of Constraint Programming and Stochastic Search: The Sudoku Case

Logic Masters India Presents

Dutch Sudoku Advent 1. Thermometers Sudoku (Arvid Baars)

Kenken For Teachers. Tom Davis January 8, Abstract

SudokuSplashZone. Overview 3


ISudoku. Jonathon Makepeace Matthew Harris Jamie Sparrow Julian Hillebrand

Welcome to the Sudoku and Kakuro Help File.

Cracking the Sudoku: A Deterministic Approach

Solution Algorithm to the Sam Loyd (n 2 1) Puzzle

Spring 06 Assignment 2: Constraint Satisfaction Problems

Exploring Strategies to Generate and Solve Sudoku Grids. SUNY Oswego CSC 466 Spring '09 Theodore Trotz

Take Control of Sudoku

Final Project: Verify a Sudoku Solution Due Fri Apr 29 (2400 hrs)? Wed May 4 (1200 hrs)? 1

KenKen Strategies 17+

Yet Another Organized Move towards Solving Sudoku Puzzle

isudoku Computing Solutions to Sudoku Puzzles w/ 3 Algorithms by: Gavin Hillebrand Jamie Sparrow Jonathon Makepeace Matthew Harris

The remarkably popular puzzle demonstrates man versus machine, backtraking and recursion, and the mathematics of symmetry.

An improved strategy for solving Sudoku by sparse optimization methods

Episode 3 8 th 12 th February Substitution and Odd Even Variations By Kishore Kumar and Ashish Kumar

Logic Masters India Presents. April 14 16, 2012 April 2012 Monthly Sudoku Test INSTRUCTION BOOKLET

CMPT 310 Assignment 1

Episode 4 30 th March 2 nd April 2018 Odd Even & Substitution Variations By R Kumaresan and Amit Sowani

DOWNLOAD OR READ : SUDOKU LARGE PRINT PUZZLE BOOK FOR ADULTS 200 MEDIUM PUZZLES PUZZLE BOOKS PLUS PDF EBOOK EPUB MOBI

Spring 06 Assignment 2: Constraint Satisfaction Problems

Sudoku Solvers. A Different Approach. DD143X Degree Project in Computer Science, First Level CSC KTH. Supervisor: Michael Minock

An Exploration of the Minimum Clue Sudoku Problem

COCI 2008/2009 Contest #3, 13 th December 2008 TASK PET KEMIJA CROSS MATRICA BST NAJKRACI

Grade 6 Math Circles March 7/8, Magic and Latin Squares

CMSC 201 Fall 2018 Project 3 Sudoku

INSTRUCTION BOOKLET SUDOKU MASTERS 2008 NATIONAL SUDOKU CHAMPIONSHIP FINALS Q&A SESSION 10:30 10:50 PART 1 CLASSICS 11:00 11:35

of Nebraska - Lincoln

UKPA Presents. March 12 13, 2011 INSTRUCTION BOOKLET.

In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

Econ 172A - Slides from Lecture 18

More Recursion: NQueens

Applications of Advanced Mathematics (C4) Paper B: Comprehension WEDNESDAY 21 MAY 2008 Time:Upto1hour

The Mathematics Behind Sudoku Laura Olliverrie Based off research by Bertram Felgenhauer, Ed Russel and Frazer Jarvis. Abstract

Techniques for Generating Sudoku Instances

WPF SUDOKU/PUZZLE GRAND PRIX 2014 WPFSUDOKU GP 2014 COMPETITIONBOOKLET ROUND6. Puzzle authors: Bulgaria Deyan Razsadov.

Mega Sudoku 16x16 - Facile - Volume Puzzle (Italian Edition) By Nick Snels READ ONLINE

Topic 10 Recursive Backtracking

Monthly Sudoku Contest for September th 17 th September Enthralling Sudoku By Ashish Kumar

SUDOKU Mahabharat. Episode 7 21 st 23 rd March. Converse by Swaroop Guggilam

1 Recursive Solvers. Computational Problem Solving Michael H. Goldwasser Saint Louis University Tuesday, 23 September 2014

Sudoku Mock Test 5. Instruction Booklet. 28 th December, IST (GMT ) 975 points + Time Bonus. Organized by. Logic Masters: India

Episode 6 9 th 11 th January 90 minutes. Twisted Classics by Rajesh Kumar

Episode 5 12 th 14 th December. Outside Variations by Rishi Puri

LMI SUDOKU TEST 7X JULY 2014 BY RICHARD STOLK

SUDOKU Mahabharat. Episode 3 15 th 17 th November. Odd Even Variations by Deb Mohanty

GET OVERLAPPED! Author: Huang Yi. Forum thread:

Overview. Initial Screen

KenKen Strategies. Solution: To answer this, build the 6 6 table of values of the form ab 2 with a {1, 2, 3, 4, 5, 6}

LMI Monthly Test May 2010 Instruction Booklet

WPF SUDOKU/PUZZLE GRAND PRIX 2014 WPF SUDOKU GP 2014 COMPETITION BOOKLET ROUND 4. Puzzle authors: Russia Andrey Bogdanov, Olga Leontieva.

LMI Sudoku test Shapes and Sizes 7/8 January 2012

Modelling Sudoku Puzzles as Block-world Problems

CMPT 310 Assignment 1

WPF SUDOKU GP 2014 ROUND 2 WPF SUDOKU/PUZZLE GRAND PRIX Puzzle authors: Serbia. Organised by

SUDOKU SURPRISE. Hosted by Logic Masters India November Puzzles set by David McNeill Tested by Tom Collyer, Yuhei Kusui and Robert Vollmert

A year ago I investigated a mathematical problem relating to Latin squares. Most people, whether knowing it or not, have actually seen a Latin square

Assignment 6 Play A Game: Minesweeper or Battleship!!! Due: Sunday, December 3rd, :59pm

Some results on Su Doku

puzzles may not be published without written authorization

Assignment 3: Fortress Defense

G53CLP Constraint Logic Programming

Eight Queens Puzzle Solution Using MATLAB EE2013 Project

NAME : SUDOKU MASTERS 2008 FINALS PART 1 CLASSICS. 1. Classic Sudoku Classic Sudoku Classic Sudoku 50

Heuristics, and what to do if you don t know what to do. Carl Hultquist

1st UKPA Sudoku Championship

expert sudoku C08AF111E38FF93DB6AF118C2DC9B2A6 Expert Sudoku 1 / 6

This chapter gives you everything you

CSE Day 2016 COMPUTE Exam. Time: You will have 50 minutes to answer as many of the problems as you want to.

The mathematics of Septoku

Table of Contents. Table of Contents 1

Sudoku. How to become a Sudoku Ninja: Tips, Tricks and Strategies

CS61B Lecture #33. Today: Backtracking searches, game trees (DSIJ, Section 6.5)

sudoku 16x16 454BB8EA3E376999F4F40AF890078C0E Sudoku 16x16 1 / 6

Physical Zero-Knowledge Proof: From Sudoku to Nonogram

A B O U T T H E S E P U Z Z L E S

For Better Brains. SUDOKU ROYALE! INSTRUCTION BOOK

CS61B Lecture #22. Today: Backtracking searches, game trees (DSIJ, Section 6.5) Last modified: Mon Oct 17 20:55: CS61B: Lecture #22 1

UK Puzzle Association Sudoku Championship 2012 All puzzles by Gareth Moore

SUDOKU1 Challenge 2013 TWINS MADNESS

Indian Sudoku Championship 2015

CS61B, Fall 2014 Project #2: Jumping Cubes(version 3) P. N. Hilfinger

Sudoku Online Qualifiers2017

NEGATIVE FOUR CORNER MAGIC SQUARES OF ORDER SIX WITH a BETWEEN 1 AND 5

PART 2 VARIA 1 TEAM FRANCE WSC minutes 750 points

Applications of Advanced Mathematics (C4) Paper B: Comprehension INSERT WEDNESDAY 21 MAY 2008 Time:Upto1hour

Beyond Prolog: Constraint Logic Programming

A Retrievable Genetic Algorithm for Efficient Solving of Sudoku Puzzles Seyed Mehran Kazemi, Bahare Fatemi

UK SENIOR MATHEMATICAL CHALLENGE

The Logic Of Sudoku By Andrew C Stuart

Transcription:

Sudoku Solver Version: 2.5 Due Date: April 5 th 2013 Summary: For this assignment you will be writing a program to solve Sudoku puzzles. You are provided with a makefile, the.h files, and cell.cpp, and a master solution named master_solver. You are not to alter any of the provided files. You are expected to complete the following: 1. The driver for the program (named driver.cpp) 2. The.cpp implementation for sudoku.h (named sudoku.cpp) 3. The UML diagram for the program Input will only ever consist of., the numbers from 1 to 9 inclusively, or potentially spaces. You are not responsible for checking to make sure input is valid. There are no restrictions on the potential input you are to account for every possible initial marking of the cells. Your program is to either produce a solved Sudoku puzzle for the corresponding input or an error message stating that there is no solution. In cases where correct input can produce multiple valid solutions, your implementation is to provide only one of the valid solutions and exit with a value of 0. If the input does not have a solution you are to print a descriptive error message, to standard error, that begins with the word ERROR and exit the program with a value of 0. Your program must use recursion to implement the backtracking method You may only implement and use the methods described below to solve a puzzle Your program should have no memory leaks. Glossary: Box: Refers to one of the 9, 3x3 matrices, found in a Sudoku puzzle Candidate: A possible value of a cell Determined Candidate: The value of the only possible candidate in a solved cell Failure: A guess that resulted in an incorrect puzzle Finalize a Cell: The process of removing all impossible candidates from a solvable cell and leaving it with only one remaining candidate. Puzzle: The 9x9 grid of a Sudoku puzzle Solvable Cell:

A cell for which we can finalize Solved Cell: A cell that has only one possible candidate remaining. Solved Puzzle: A solution to the given Sudoku puzzle Background: Sudoku is a number based puzzle game. The objective of Sudoku is to fill in every cell in the 9x9 grid with a number from 1 to 9. Valid solutions to a Sudoku puzzle comply with the following rules: Cell values given in the initial puzzle must not be changed. Each row must contain the numbers from 1 to 9 Each column must contain the numbers from 1 to 9 Each of the nine 3x3 boxes must contain the numbers from 1 to 9 Below are two example Sudoku puzzles and a corresponding solution to each puzzle: 1 5 6 7 2 1 4 5 3 9 8 1 4 6 7 1 4 5 9 8 3 6 7 2 8 2 4 3 8 9 7 6 2 4 5 1 6 3 7 1 2 6 3 5 7 4 8 1 9 9 3 9 5 8 6 2 1 7 4 3 1 9 5 2 7 1 4 3 9 8 5 2 6 7 2 8 5 9 7 2 3 6 1 8 4 2 6 3 5 4 2 6 8 1 7 9 3 5 4 9 8 3 1 4 5 9 2 6 7 4 2 8 7 3 5 1 6 4 9 2 8 4 6 5 4 2 6 9 7 8 3 1 5 1 3 6 1 9 8 5 3 2 6 7 4 3 1 2 4 9 3 8 1 7 5 6 8 7 1 4 3 8 7 2 5 6 1 4 9 7 9 5 6 1 7 4 9 8 3 2 2 1 3 8 5 2 6 1 7 4 9 3 9 5 7 9 1 4 8 2 3 5 6 7 6 7 4 6 7 3 4 9 5 2 8 1

Algorithm: Using the above rules here are 5 methods that you are to use to solve any Sudoku puzzle. Method 1 Cell Refinement: When a cell is solved (there is only one possible candidate remaining) we finalize the cell and eliminate the possibility of that candidate from all cells in the same row, column, and box (3x3 grouping of cells). If eliminating this candidate solves another cell then we repeat this method on the solvable cell. Method 2 Row Check: Utilizing the rule each row must contain the numbers from 1 to 9 we can potentially solve more cells. Specifically, any cell with a candidate not found in the other cell in the same row can be solved for that candidate. For such cells we apply Method 1 on the solvable cell. Method 3 Colum Check: Method 3 works the same way as Method 2 but for columns. For each solvable cell, we apply Method 1 on the solvable cell. Method 4 Box Check: Method 4 works the same way as Method 2 but for boxes. For each solvable cell, we apply Method 1 on the solvable cell. Method 5 Backtracking: Methods 1 through 4 will not always produce a solved Sudoku puzzle. For these situations we must guess what the correct candidate of a particular cell is so that we can progress. To do this we will implement a recursive backtracking algorithm. If an incorrect guess is made the backtracking algorithm will allow us to return to the state of the puzzle before we make a guess, from here we can make a new guess. These guesses will either lead to a solved puzzle, a failure, or a state that requires another guess to be made. In the case of a failure we will (in order): 1. Free all memory from the puzzle that caused the failure. 2. Return a value indicating that our guess was a failure. 3. Make a new guess on the cell with the least number of possible candidates. To reduce the number of potential incorrect guesses, first search for the cell that contains the least possible candidates, then make a guess on the candidate with the smallest value in the found cell. In the case where the input given has no solution you are to produce an error message beginning with the word ERROR that details the error and exit your program after with a value of 0.

Pseudo Code: The following is the pseudo code for the recursive backtracking algorithm you must implement in your driver to solve Sudoku puzzles. Sudoku* solve (Sudoku* puzzle) { Method 2; Method 3; Method 4; //finalize all solvable cells and eliminate the determined //candidate form all related cells. Method 1; } if (failure) return NULL; else if (puzzle is solved) return puzzle; else if (no more solvable cells) { //Create a new puzzle with a cell finalized to the //guessed candidate and eliminate the guessed //candidate from the original puzzle. newpuzzle = guess (puzzle); solve (newpuzzle); if (the guess was a failure) return solve (puzzle); return newpuzzle; } else return solve (puzzle); Implementation/Purpose: Cell Class: The purpose of this class is to store the possible candidates of a given cell. Do not modify the cell.h or cell.cpp file in any way. Note: candidates[0] corresponds to what whether or not the value 1 is a candidate for the cell. Furthermore, candidates[1] corresponds to whether or not the value 2 is a candidate for the cell not value 1. Sudoku Class: This class is meant to represent an actual Sudoku puzzle. It will be used to implement methods 1 to 4. The class contains a 9x9 2D array of pointers to Cells. The sudoku.h file is not to be modified in any way. Driver: The driver for your program is will recursively implement the backtracking method as well as the calls to the other methods in the algorithm as detailed above.

Input: Your program is to accept input from standard input Input will only ever consist of., the numbers from 1 to 9 inclusively, or potentially spaces. You are not responsible for checking to make sure input is valid.. represents a cell for which we are not give the finalized value A space is not guaranteed to be in the input, nor is it guaranteed that the input will be formatted in the ways presented below The only other valid input is a number from 1 to 9 The following are examples of the input format you may be given:..... 4. 2 8 4. 6..... 5 1... 3. 6..... 3. 1.... 8 7... 1 4.... 7. 9..... 2. 1... 3 9..... 5. 7 6 7. 4..... OR...4.284.6...51...3.6...3.1...87...14...7.9...2. 1...39...5.767.4... Output: Your program should always begin by printing the input as follows and then a new line in the following way:..... 4. 2 8 4. 6..... 5 1... 3. 6..... 3. 1.... 8 7... 1 4.... 7. 9..... 2. 1... 3 9..... 5. 7 6 7. 4..... If there is no solution, you are to print an appropriate error message to standard error beginning with the word ERROR and exit the program with a value of 0. If there is a solution to the given input you are to print out the solved puzzle in the way shown above. For more detail on the output of the program you are to test your input against the provided master solution

Assignment Specifications: a6p1: Create sudoku.cpp Write the implementation for all functions found in the file suodku.h. Name this file sudoku.cpp. Your sudoku.cpp file is to #include only the following: sudoku.h Zip the following files into to a6p1.zip and submit the zip file to a6p1 on Marmoset: sudoku.cpp a6p2: Create driver.cpp Write the driver for the Sudoku solver. Your driver is to implement the algorithm described above. Name this file driver.cpp. Your driver.cpp file is to #include only the following: <iostream> <cstdlib> sudoku.h Zip the following files into to a6p2.zip and submit the zip file to a6p2 on Marmoset: sudoku.cpp driver.cpp a6p3: Create the UML Create the UML diagram for the program. Save your UML diagram to a PDF file and name the file SudokuUML.pdf. Submit the following files to a6p3 on Marmoset: SudokuUML.pdf Marking Scheme: Question Marks a6p1 30 a6p2 50 a6p3 10 Style 10 ~ contributed by Richard Bruce Wallace