4.3

4.3 | 20 ratings Rate this file 24 downloads (last 30 days) File Size: 43.48 KB File ID: #7676

Sudoku

by Stefan Bleeck

 

17 May 2005 (Updated 20 Dec 2005)

No BSD License  

Sudoku for MATLAB.

Editor's Notes:

This file was a File Exchange Pick of the Week

Download Now | Watch this File

File Information
Description

Sudoku is a game that is very fashinable in Britain at the moment. Everyone seems to be captured.

The rules are very simple:
Fill in the grid so that every row, every column, and every 3x3 box contains the digits 1 through 9.

That's all there is to it. There's no math involved. The grid has numbers, but nothing has to add up to anything else. You solve the puzzle with reasoning and logic. It's fun. It's challenging. It's addictive!

I tried one of these puzzles last Sunday and spent the rest of the afternoon with the Times on my lap scribbling little numbers only to find out after hours that my first guess was wrong and I had to restart. How frustrating!

So I decided to solve this problem once for all. Why must I think when that can be done by my computer?

You can use the program for solving sudokus yourself (and get some help if you need it) or let the computer solve them for you (much more satisfactory :)

You can also generate your own puzzles. But please be aware that the generating option is not too sophisticated. It works by basically finding a solution to a random sudoku and then taking away random numbers.
A simple rule is applied to see if the puzzle is unique: the solution of the puzzle is compared to the solution of the transposed puzzle. If both are the same then the puzzle is very probable unique. For difficult puzzles this sometimes takes some time.

-------INSTALLATION---------
unzip sudoku.zip (the zip contains also the gui-files, so its some files. The actual sudoku file is only one .m-file)

change into the created directory
type "sudoku"
A figure appears in the top right corner that gives you options:
"Emtpy puzzle" creates an empty field that you can fill with whatever you like
"file name" declares the name of the file that you can save or load (the latest one from the Times is in "sudoku_saved").
"load puzzle" loads the puzzle with the filename.
"save puzzle" saves the current puzzle under the filename.
"check possible" plots small pencilmarkers for all possible entries (that are all entries that are not conflicting with the existing entries).
"check neccessary" checks all fields if its neccessary to be filled with a number (checks each line, column and subsquare for fields in which only one number can go).
"solve" uses the two methods and finds a solution recursivly.

Start with loading the suggested puzzle (its a very tough one!) You can try to solve it yourselve by clicking into a square and insert a number between 1 and 9. If you type in 0 the square is cleared. If its not a valid number (contradicts the rules as stated above) the number is printed in red.

Pressing the "check possible" button shows you what numbers are possible at every given time.

Try to solve an empty puzzle or create some that have funny properties (e.g all magic squares...)

If you are looking for more puzzles try eg
www.timesonline.co.uk/section/0,,18209,00.html or
www.griffiths-jones.co.uk/sudoku/

FAQ:
Q: When I start your program get the message
??? Undefined function or variable 'uipanel'.
A: Sorry, you need MATLAB version 7 for this program

Q:??? Error using ==> class
Class parameter is not a valid class name...
A: this error results from a wrong zip-file. Its solved now.

If for what ever reason the gui appears partly out of the screen, type in "movegui", to recenter it

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Create Interactive GUIs

MATLAB release MATLAB 7 (R14)
Zip File Content  
Other Files
sudoku/@parameter/add.asv,
sudoku/@parameter/add.m,
sudoku/@parameter/disablefield.m,
sudoku/@parameter/disp.m,
sudoku/@parameter/display.m,
sudoku/@parameter/enable.m,
sudoku/@parameter/enablefield.m,
sudoku/@parameter/exist.m,
sudoku/@parameter/get.m,
sudoku/@parameter/getas.m,
sudoku/@parameter/getcurrentunit.m,
sudoku/@parameter/getdefaultbutton.m,
sudoku/@parameter/getentrybyhandle.m,
sudoku/@parameter/getentrynumberbytext.m,
sudoku/@parameter/getfirstfocus.m,
sudoku/@parameter/gethandle.m,
sudoku/@parameter/getmode.m,
sudoku/@parameter/getname.m,
sudoku/@parameter/getposition.m,
sudoku/@parameter/getradiobutton.m,
sudoku/@parameter/getraw.m,
sudoku/@parameter/getstringvalue.m,
sudoku/@parameter/gettext.m,
sudoku/@parameter/getuserdata.m,
sudoku/@parameter/getversion.m,
sudoku/@parameter/parameter.m,
sudoku/@parameter/set.m,
sudoku/@parameter/setas.asv,
sudoku/@parameter/setas.m,
sudoku/@parameter/setcallback.m,
sudoku/@parameter/setfirstfocus.m,
sudoku/@parameter/sethandle.m,
sudoku/@parameter/setmode.m,
sudoku/@parameter/setposition.m,
sudoku/@parameter/setradiobutton.m,
sudoku/@parameter/setslidereditcontrol.m,
sudoku/@parameter/setstringvalue.m,
sudoku/@parameter/settooltip.m,
sudoku/@parameter/setuserdata.m,
sudoku/parametergui.m,
sudoku/sudoku.m,
sudoku/sudoku_saved.mat
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (20)
21 May 2005 daniel miler

fantastic just brilliant

31 May 2005 Mat Labor

Great program, easy to use, Intuitive, in one word - excellent!

01 Jul 2005 Luc Jonckheere

Great program!

06 Jul 2005 wayne kiernan

Great Game

15 Jul 2005 Brett Shoelson

Stefan...very nice! I'm getting hooked on these damned things. But I have one suggestion: "proper" sudoku puzzles should have unique solutions; yours often do not. A modification to ensure uniqueness would be nice.

28 Jul 2005 Sun Liantao

Fantastic!I thing it's more amused than "the game of go".Let's thank the author.

12 Aug 2005 Joe Lastname

Really liked the game. I found it interesting that I could alter the numbers given to me by the computer.

15 Aug 2005 T M  
27 Oct 2005 Robert Adams

Handy for Sudoku addicts. One problem, on my system with 1600x1200 resolution the parameter gui is located in the upper left corner of the screen and is partially off of the screen.

03 Nov 2005 Georg Ogris

(1) the GUI has got some bugs
(2) bad programming style
(3) Due to the fact that the Sudokus are generated by deleting random entries there is no warranty that the sudokus are uniquely solvable and in fact all the "difficult" and most of the "mild" and most of the "easy" sudokus I tested had more than one solution.

20 Nov 2005 Maurice Hendrix

Brilliant

15 Dec 2005 J Mook

Release 14, I get the error:

??? Error using ==> class
Class parameter is not a valid class name.

Error in ==> parameter at 90
dstr=class(param,'parameter');

Error in ==> sudoku at 34
    params=parameter('sudoku controls');

17 Dec 2005 S Vora

Error results as follows : release R14 service pack 1
??? Error using ==> class
Class parameter is not a valid class name.

Error in ==> parameter at 90
dstr=class(param,'parameter');

Error in ==> sudoku at 34
    params=parameter('sudoku controls');

09 Jan 2006 Matthias Isler  
14 Jan 2006 Torkil Deigaard

Remember to select "Include folder information" when unzipping. This creates the @parameter directory for storing the parameter class.

12 Feb 2006 David Trumper

I really enjoyed using this, and have been giving my kids puzzles generated with your code. Thanks!

12 Apr 2006 Hoa Ngo  
03 Dec 2006 Omer Demirkaya

I am also novice sudoku player. Last night it occurred to me that this could be programmed in Matlab. As usual, first thing in the morning I checked Matlab File Exchange not to rediscover the wheel. And here it is! Excellent job! Thanks.

09 Oct 2007 Lucas Lopes

Very good...
I never see something like these in matlab progamation...
Tanks....and exuse-me for the bad english

11 Nov 2007 Andres .

Nice Job. It would be even better to have the suggested numbers in a diferent color so they don't are confused with the ones I guess.
Regards
Andres

Please login to add a comment or rating.
Updates
19 May 2005

added rules to description

07 Jun 2005

added generation routine
fixed a bug that prevented it from finding solutions

28 Oct 2005

bug correction

22 Nov 2005

update of text and small bug fixes

07 Dec 2005

rule for uniqueness added

20 Dec 2005

updated FAQ, correcteted zip archive

Tag Activity for this File
Tag Applied By Date/Time
games Stefan Bleeck 22 Oct 2008 07:48:52
sudoku Stefan Bleeck 22 Oct 2008 07:48:52
su doku Stefan Bleeck 22 Oct 2008 07:48:52
puzzle Stefan Bleeck 22 Oct 2008 07:48:52
game Stefan Bleeck 22 Oct 2008 07:48:52
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com