Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org How to generate the Sudoku puzzle from solved solution?
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 02-26-2009, 08:29 PM #1 pumpkin LQ Newbie   Registered: Feb 2009 Posts: 10 Rep: How to generate the Sudoku puzzle from solved solution? Hi everybody, (I searched entire forum before create this new thread!) I'm currently writing a Sudoku game for me now. I have already generated the Sudoku solutions from a solved solution (by using shuffle groups or lines) and from the empty Sudoku board (by backtracking algorithm). Now I'm confusing when I want to generate the Sudoku puzzle from the solved solutions - removing some values from squares flows three levels: Hard, Medium and Easy. Are you advanced in the Sudoku game? Let me know your experiences in my gratitude! Your helps are valuable presents for me! Thanks and best regards!
 02-26-2009, 09:08 PM #2 wje_lq Member   Registered: Sep 2007 Location: Mariposa Distribution: FreeBSD,Debian wheezy Posts: 811 Rep: You can learn much from studying the source code of others. You'll find sudoku generators of varying quality and in various languages here. Hope this helps.
 02-27-2009, 12:58 AM #3 ta0kira Senior Member   Registered: Sep 2004 Distribution: FreeBSD 9.1, Kubuntu 12.10 Posts: 3,078 Rep: Something you might not learn without a lot of hacking is how to strategically remove numbers so that the puzzle is still solvable and still has only one solution. I don't know how to do that, but in my opinion, that sounds like a lot more work than generating the solved puzzle (at least comparable to the difficulty level you hope to achieve.) You probably need a strong algorithm. I doubt all of the free sudoku projects take that into account; some probably give you an unsolvable puzzle without knowing it. Then again, this is all just ignorant speculation. Kevin Barry Last edited by ta0kira; 02-27-2009 at 12:59 AM.
02-27-2009, 04:40 AM   #4
wje_lq
Member

Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep:
Quote:
 You probably need a strong algorithm. I doubt all of the free sudoku projects take that into account; some probably give you an unsolvable puzzle without knowing it.
A brief review of the google results suggests that some of the projects address these issues more carefully than others. One of the most promising ones (judging by its blurb) was tempting enough that I actually tried running it, and it blew up with a setjmp error, whatever that is.

 02-27-2009, 08:38 AM #5 bigearsbilly Senior Member   Registered: Mar 2004 Location: england Distribution: Debian, Mint, Puppy, Raspbian Posts: 3,421 Rep: well, the obvious method is staring you in the face you've already done it! get a solution, 1. remove some numbers, 2. run it through your solver 3. repeat maybe make some metrics in your solver on how many steps the solution takes? or depth of backtrack etc.
02-28-2009, 04:04 AM   #6
ta0kira
Senior Member

Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep:
Quote:
 Originally Posted by wje_lq A brief review of the google results suggests that some of the projects address these issues more carefully than others. One of the most promising ones (judging by its blurb) was tempting enough that I actually tried running it, and it blew up with a setjmp error, whatever that is.
setjmp sets a reference point on the stack for use later, then a call to longjmp unwinds the stack back to that point. I can't think of any good reason to have that in Sudoku. Really the only reason I could see using it is implementation of an exception system.
Kevin Barry

02-28-2009, 04:07 AM   #7
ta0kira
Senior Member

Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep:
Quote:
 Originally Posted by bigearsbilly well, the obvious method is staring you in the face you've already done it! get a solution, 1. remove some numbers, 2. run it through your solver 3. repeat maybe make some metrics in your solver on how many steps the solution takes? or depth of backtrack etc.
While probably effective, that's a somewhat unintelligible way to do it. This would be a great opportunity to practice algorithm design and problem analysis.
Kevin Barry

 02-28-2009, 04:14 AM #8 ta0kira Senior Member   Registered: Sep 2004 Distribution: FreeBSD 9.1, Kubuntu 12.10 Posts: 3,078 Rep: (accidentally posted twice because of database crash)
 03-01-2009, 05:23 AM #9 pumpkin LQ Newbie   Registered: Feb 2009 Posts: 10 Original Poster Rep: (My English is very bad) Thanks everyone for your replies although I'm still not found out what I need. I'm currently reading some open source code of Sudoku game. I hope that I can find out solution for my problems. I've generated my puzzles but there are a few solutions for each of them, but what I need is a puzzle that there is only one solution. Thanks everyone again, I'm waiting for your help! Kind regards and greetings to LQ's members ^^ Last edited by pumpkin; 03-01-2009 at 05:28 AM.

 Tags from, generate, how, solution

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post LXer Syndicated Linux News 0 02-02-2008 07:41 AM LXer Syndicated Linux News 0 03-01-2007 12:31 PM demerson3 LQ Suggestions & Feedback 12 04-08-2006 02:15 PM ewt3y Programming 21 08-30-2005 12:09 PM adengua Linux - Software 0 04-02-2004 03:34 AM

All times are GMT -5. The time now is 04:26 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -