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

Similar documents
A Tic Tac Toe Learning Machine Involving the Automatic Generation and Application of Heuristics

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

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

Automatically Generating Puzzle Problems with Varying Complexity

Cracking the Sudoku: A Deterministic Approach

AllegroCache Tutorial. Franz Inc

SudokuSplashZone. Overview 3

8. You Won t Want To Play Sudoku Again

Mobile SuDoKu Harvesting App

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

Sudoku Touch. 1-4 players, adult recommended. Sudoku Touch by. Bring your family back together!

Python for education: the exact cover problem

ON 4-DIMENSIONAL CUBE AND SUDOKU

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

ISudoku. Jonathon Makepeace Matthew Harris Jamie Sparrow Julian Hillebrand

An improved strategy for solving Sudoku by sparse optimization methods

BMT 2018 Combinatorics Test Solutions March 18, 2018

Techniques for Generating Sudoku Instances

Spring 06 Assignment 2: Constraint Satisfaction Problems

Investigation of Algorithmic Solutions of Sudoku Puzzles

A Group-theoretic Approach to Human Solving Strategies in Sudoku

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

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

ENGR170 Assignment Problem Solving with Recursion Dr Michael M. Marefat

patterns in mathematics unit 3 notes.notebook Unit 3: Patterns in Mathematics

Welcome to the Sudoku and Kakuro Help File.

Spring 06 Assignment 2: Constraint Satisfaction Problems

Informatica Universiteit van Amsterdam. Performance optimization of Rush Hour board generation. Jelle van Dijk. June 8, Bachelor Informatica

Taking Sudoku Seriously

Yet Another Organized Move towards Solving Sudoku Puzzle

Selected Game Examples

Take Control of Sudoku

sudoku 16x16 454BB8EA3E376999F4F40AF890078C0E Sudoku 16x16 1 / 6

More Recursion: NQueens

REVIEW ON LATIN SQUARE

Using Artificial intelligent to solve the game of 2048

The University of Algarve Informatics Laboratory

Latin Squares for Elementary and Middle Grades

Design and Implementation of Game Based Security Model to Secure the Information Contents

Lisp: Case Study ref: Lisp (3 rd Ed) Winston & Horn (Chapter 6) Donald F. Ross

CMPT 310 Assignment 1

CMSC 201 Fall 2018 Project 3 Sudoku

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

Sudoku: Is it Mathematics?

puzzles may not be published without written authorization

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

Solving and Analyzing Sudokus with Cultural Algorithms 5/30/2008. Timo Mantere & Janne Koljonen

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

Logic Masters India Presents

The KNIME Image Processing Extension User Manual (DRAFT )

Python for Education: The Exact Cover Problem

Describes the operation of multiplying by ten as adding a nought

Classwork Example 1: Exploring Subtraction with the Integer Game

Part III F F J M. Name

SUDOKU X. Samples Document. by Andrew Stuart. Moderate

! Denver, CO! Demystifying Computing with Magic, continued

The mathematics of Septoku

Implementation of Recursively Enumerable Languages in Universal Turing Machine

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

Olympiad Combinatorics. Pranav A. Sriram

Modelling Sudoku Puzzles as Block-world Problems

CMPT 310 Assignment 1

Hill-Climbing Lights Out: A Benchmark

Kenken For Teachers. Tom Davis January 8, Abstract

The most difficult Sudoku puzzles are quickly solved by a straightforward depth-first search algorithm

You ve seen them played in coffee shops, on planes, and

Sudoku Book: 200 Sudoku Puzzles Of All Difficulties (Volume 2) By Djape READ ONLINE

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

GET OVERLAPPED! Author: Huang Yi. Forum thread:

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

Tetrabonacci Subgroup of the Symmetric Group over the Magic Squares Semigroup

For Better Brains. SUDOKU ROYALE! INSTRUCTION BOOK

T H E M A T H O F S U D O K U

Synthesizing Interpretable Strategies for Solving Puzzle Games

Beyond Prolog: Constraint Logic Programming

HP-71B Sudoku Generator... & Coach!

Sudoku: More Than 200 Fun And Challenging Japanese Number Puzzles By Tammy Seto READ ONLINE

Enumerating 3D-Sudoku Solutions over Cubic Prefractal Objects

It Stands to Reason: Developing Inductive and Deductive Habits of Mind

Mathematics of Magic Squares and Sudoku

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

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

Solving Who Am I? Puzzles. Building Who Am I? Puzzles. t u Who Am I? The product of my digits is 16. The sum of my digits is 8. Who Am I?

CPM Educational Program

of Nebraska - Lincoln

Minimum Zero-Centre-Pandiagonal Composite Type II (a) Magic Squares over Multi Set of Integer Numbers as a Semiring

Colossal Cave Collection Sampler

Overview. The Big Picture... CSC 580 Cryptography and Computer Security. January 25, Math Basics for Cryptography

The patterns considered here are black and white and represented by a rectangular grid of cells. Here is a typical pattern: [Redundant]

Dice Activities for Algebraic Thinking

CS/COE 1501

UKPA Presents. March 12 13, 2011 INSTRUCTION BOOKLET.

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

Some results on Su Doku

FreeCell Puzzle Protocol Document

A. Rules of blackjack, representations, and playing blackjack

Week 1 Assignment Word Search

Simon Nestler Florian Echtler Andreas Dippon Gudrun Klinker

A comparison of a genetic algorithm and a depth first search algorithm applied to Japanese nonograms

Arithmetic Sequences Read 8.2 Examples 1-4

Transcription:

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

Terminology A Sudoku grid contains 81 cells Each cell is a member of a particular region, row, and column There are 9 regions, rows and columns each contains 9 cells A B C D E F G H I ------------------------- 1 2 NW N NE 3 -------+-------+------- 4 5 W C E 6 -------+-------+------- 7 8 SW S SE 9 -------------------------

Objective The goal of Sudoku is to fill each cell such that the numbers 1-9 appear only once in each region, column, and row A B C D E F G H I ------------------------- 1 1 6 5 7 4 3 8 2 9 2 2 3 7 9 5 8 6 1 4 3 8 9 4 1 2 6 7 5 3 -------+-------+------- 4 9 1 6 2 8 7 4 3 5 5 3 7 8 4 1 5 9 6 2 6 5 4 2 3 6 9 1 8 7 -------+-------+------- 7 7 5 3 8 9 1 2 4 6 8 4 8 9 6 3 2 5 7 1 9 6 2 1 5 7 4 3 9 8 ------------------------- Board Consistency: T

Motivation Sudoku is new to the family of logic games Sudoku Player Forums Other peoples programs Few Sudoku Programs in Lisp 5,472,730,538 Sudoku boards after equivalence classes have been removed

Representation Each region contains an association list for the enclosed cells Rows of the board are fetched by conjoining three regions, and then passing an offset to get the desired row Columns work in a similar manner Required to board consistency

Backtracking Analogous to Guess and Check For each cell loop: Populate a list of 9 random numbers 1-9 - no duplicates Pop the first random number off the list and set that value to the current cell If the board is valid If the next cell returns true, return true from recursion Else set cell to empty Return NIL http://moxie.cs.oswego.edu/~trotz/csc466/sudoku/backtracking_demo.txt

User Interface Current Stage Checks Board Consistency Generates Complete Grids Load in / print out a string of length 81 representing a board configuration

Features To Be Added Removal of cells from completed grid to allow the user to play interactively Beat the Clock Game Play General Sudoku Solver Almost There Store / Load Boards

Code Segments ; IN: A zero-indexed offset to select a column AND the ; region list to which the column belongs ; OUT: A list of arity 3 which is the a-list of the column (defmethod get-region-col ((offset integer (region list &optional col (cond ((eq (nth offset region nil col ((and (> offset 2 (null col ; Do not allow initial offsets greater than 2 as ;the output is not valid nil (t (get-region-col (+ offset 3 region (append col (list (nth offset region ; IN: An association list to check for consistency. ; OUT: Returns T if the numbers 1-9 appear only once. Returns NIL if they appear more than once. (defmethod check-cells ((alist list &aux values (setf values (extract-alist-values alist (loop for i from 1 to 9 do (setf values (remove i values :count 1 (setf values (remove 0 values (cond ((null values t (t nil ; DES: This method utilizes a backtracking algorithm to populate the list of cells given. ; IN: A board and the list of cells to be filled ; OUT: Returns T when completed. (defmethod populate-cell-backtrack ((b board (cells list &aux cell random-nums (cond ((null cells t (t (setf random-nums (nine-random-nums ( (setf cell (car (car cells (dolist (value random-nums (rplacd (assoc cell cells value (display-board b (format t "Board Consistency: ~A~%" (check-board b (if (check-board b (if (populate-cell-backtrack b (cdr cells (return-from populate-cell-backtrack t (rplacd (assoc cell cells 0 nil (defclass board ( ( (nw :accessor board-nw :initform (pairlis '(c3 b3 a3 c2 b2 a2 c1 b1 a1 '(0 0 0 0 0 0 0 0 0 (n :accessor board-n :initform (pairlis '(f3 e3 d3 f2 e2 d2 f1 e1 d1 '(0 0 0 0 0 0 0 0 0 (ne :accessor board-ne :initform (pairlis '(i3 h3 g3 i2 h2 g2 i1 h1 g1 '(0 0 0 0 0 0 0 0 0 (w :accessor board-w :initform (pairlis '(c6 b6 a6 c5 b5 a5 c4 b4 a4 '(0 0 0 0 0 0 0 0 0 (c :accessor board-c :initform (pairlis '(f6 e6 d6 f5 e5 d5 f4 e4 d4 '(0 0 0 0 0 0 0 0 0 (e :accessor board-e :initform (pairlis '(i6 h6 g6 i5 h5 g5 i4 h4 g4 '(0 0 0 0 0 0 0 0 0 (sw :accessor board-sw :initform (pairlis '(c9 b9 a9 c8 b8 a8 c7 b7 a7 '(0 0 0 0 0 0 0 0 0 (s :accessor board-s :initform (pairlis '(f9 e9 d9 f8 e8 d8 f7 e7 d7 '(0 0 0 0 0 0 0 0 0 (se :accessor board-se :initform (pairlis '(i9 h9 g9 i8 h8 g8 i7 h7 g7 '(0 0 0 0 0 0 0 0 0

#!/usr/bin/perl -w use 5.004; use CGI qw(:standard; Perl Script my $clisp = "/opt/sfw/bin/clisp -q "; #-----[ Main Routine ]--------------------------------------- print header(-type => 'text/html'; print start_html(-head => style({-type => 'text/css'}, join('',<data>,, ; displayboard(; print end_html; print "\n"; exit 0; #-----[ Subroutines ]--------------------------------------- sub displayboard { print '<pre>'; $path = "/home/trotz/public-html/csc466/cgi/sudoku-cgi.fas"; system $clisp. $path; print '</pre>'; } DATA pre { text-align: center; }

Questions?

References [1] Delahaye, Jean-Paul. The Science Behind SUDOKU. Scientific American 294.6 (June 2006: 80 87. Business Source Premier. EBSCO. 23 Feb. 2009 [2] Chang,Christopher. hsolve: A Difficulty Metric and Puzzle Generator for Sudoku. 2008. [3] Chandwick, Seth. Ease and Toil: Analyzing Sudoku. UMAP 29(2008: 363-379. [4] Dahl, Geir. Permutation matracies related to Sudoku. Linear Algebra and its Applications (2008: 1-7 [5] Santos-Garcia, Gustavo. Solving Sudoku Puzzles with Rewriting Rules. Electronic Notes in Theoretical Computer Science 176(2007 79-93. [6] Schreiner, Axel. Sudoku A little lesson in OOP. ACM SIGCSE Bullitin 40(2008: 44-47. [7] Hui-Dong, MO. Sudoku Square a New Design in Field Experiments. ACTA Argonomica Sinica 34(2008: 1489-1493. [8] Boyer, Christian. Sudoku's French Ancestors Solutions to the Problems. Math Intel 29(2007: 41-44. [9] Glaister, Elizabeth. Su Doku. Mathematics in School 34(2005: 2-3. [10] Martin, David. Cracking the Sudoku: A Deterministic Approach. UMAP 29(2008: 381-394.