Thread: 25x25 sudoku

  1. #16
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Hmm... I thought all sudoku puzzles are of your "easy" difficulty (for the most parts).

    Guess that won't hold for harder puzzles (and I don't know what XY-wing is, I think I should look into it).

    Right now I am just optimizing my brute-force approach. It can solve the 16x16 puzzle I posted above in 6 seconds now.

  2. #17
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by iMalc View Post
    I don't know why you're saying that. I'll define "branching factor" to mean how many numbers have not yet been eliminated for the cell with the lowest number of non-eliminated values.
    consider
    Code:
    |  |  |  ||  |  |  ||* |* |  |
    |* |  |  ||* |  |  ||  |  |  |
    |  |* |  ||  |* |  ||  |  |  |
    ==============================
    |* |  |  ||* |  |  ||  |  |  |
    |  |* |  ||  |* |  ||  |  |  |
    |  |  |  ||  |  |  ||* |* |  |
    ==============================
    |  |  |* ||  |  |* ||  |  |  | 
    |  |  |* ||  |  |  ||  |  |* | 
    |  |  |  ||  |  |* ||  |  |* |
    where an * represents a box with exactly 2 possibilities, this puzzle would have two solutions (I think that's kinda what he meant by branching)
    Last edited by ಠ_ಠ; 06-21-2009 at 03:11 AM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #18
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Guess that won't hold for harder puzzles (and I don't know what XY-wing is, I think I should look into it).
    Here's an example of XY-wing in practice. Two must be in either tip of the "wings", as otherwise nothing could go in the square with 5 and 7. Therefore, at the intersection of these squares there cannot be a 2 and we know it is a six. From there on it is quite straightforward. (I find it impossible, though, to discover XY-wing without marking the candidates.)

    (The bonus factor here is how the eliminations of 4's in the middle right block has revealed the pattern. )

    Unfortunately, at this point the puzzle could be simply solved by guessing. Pick some of the two-candidate squares, make a choice and see whether it leads to a solution. If not, undo the moves and try the other.

    I don't think brute-force solvers are interested in such techniques, and I'm afraid 9 * 9 is too deeply hard-coded in the logical solver of this program to see how well it would do with larger puzzles.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #19
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Thanks for the great explanation! I think I get it now.

    Now we need to find a way to program that knowledge...

  5. #20
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Hours of keyboard spamming, an epiphany, and some more keyboard spamming with a lot of excitement later -

    Code:
    Node count: 668
    
    real	0m0.022s
    user	0m0.012s
    sys	0m0.004s
    (for the "difficult" 16x16 puzzle).

    Still no go for the 25x25, though. But I already have some optimization ideas.

  6. #21
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    Wow! This seems like an interesting project, I may have to create a "Sodoku Solver"

    --
    Legit

  7. #22
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I should revive my Haskell sudoku solver as well one of these days. It was pretty smart, being able to apply the "4 elimination" technique anon aluded to (but not the XY-wing technique, first time I hear of this), but was otherwise too complex and slow.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #23
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    I'm curious how your brute force approach eliminates numbers. Does it plug a value in, then run through all the possible numbers for the other cells, checking each time?

  9. #24
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    The code for my 9 by 9 solver is on my website under Useful Classes.

    Basically it checks for an invalid board, if not invalid then it copies the board, plugs in a number from one of the remaining possibilities in the cell with the least remaining probabilities, eliminates any now impossible values from any row, col or square and recurses, iirc.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #25
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Finally solved an "easy" 25x25.
    Code:
    Node count: 314769799
    
    real	346m45.039s
    user	340m32.925s
    sys	0m22.845s
    Now THAT is speed...

    Code:
    0 0 12 0 0 0 21 0 0 11 0 0 0 7 0 0 0 0 3 17 0 0 9 0 24 
    0 0 0 0 17 8 0 18 0 0 11 0 0 0 0 0 22 0 0 0 1 13 20 0 0 
    4 1 2 8 9 0 0 0 3 0 0 0 24 20 0 0 6 0 0 0 0 0 0 22 11 
    21 22 24 23 0 0 4 10 5 0 0 0 9 18 1 0 0 15 0 0 3 8 0 0 0 
    11 0 0 7 0 24 6 0 2 23 17 4 0 0 12 0 0 0 0 0 0 0 15 0 0 
    0 0 0 0 0 17 9 21 0 0 0 15 0 19 0 0 0 0 18 0 0 0 0 16 14 
    0 0 0 5 0 4 22 11 0 10 0 0 0 16 17 0 0 12 0 1 13 9 25 0 8 
    0 0 6 0 3 0 18 1 0 0 0 0 14 21 7 0 0 0 9 23 19 0 0 2 0 
    0 9 0 17 8 0 15 25 0 0 12 0 0 4 0 0 2 0 0 11 20 0 21 0 0 
    0 13 7 0 0 23 3 0 0 0 0 0 20 0 0 0 0 0 0 10 0 18 0 4 22 
    13 0 18 0 5 2 0 0 0 0 0 0 4 0 0 3 0 0 0 8 0 1 0 7 23 
    0 0 0 16 23 0 0 7 0 0 1 25 0 0 5 0 0 0 0 0 24 0 14 0 0 
    0 0 0 11 25 0 0 12 0 0 0 0 0 23 21 20 0 14 4 0 0 0 0 0 0 
    8 12 20 19 0 0 0 0 23 0 0 0 22 0 11 24 0 0 0 6 0 0 17 10 0 
    14 2 0 0 0 0 8 0 19 25 6 16 0 3 9 11 0 5 0 12 0 0 0 20 15 
    12 17 0 0 0 0 0 5 0 21 18 0 6 0 0 2 9 0 0 24 4 0 10 0 20 
    2 0 0 1 0 0 0 0 0 3 0 0 0 0 25 19 0 0 21 22 16 0 0 24 0 
    20 0 0 24 16 0 10 0 0 0 0 0 17 1 0 0 0 23 0 5 18 25 0 3 0 
    0 8 0 0 14 25 17 0 0 0 24 9 19 5 0 6 0 0 20 0 0 11 23 1 0 
    0 0 11 25 6 20 1 0 0 7 0 0 16 14 0 0 0 0 10 15 17 12 0 0 21 
    22 23 0 0 0 21 0 16 0 0 0 8 0 0 18 7 0 24 0 0 0 14 13 0 17 
    0 7 0 15 0 0 20 0 0 6 0 24 0 2 14 13 0 0 11 3 0 0 5 0 25 
    3 21 0 10 0 7 25 14 15 19 0 0 0 9 0 22 0 6 0 0 2 0 0 0 0 
    9 0 0 0 0 18 5 0 0 0 23 19 15 0 10 0 0 1 0 0 0 0 11 0 0 
    0 16 0 0 20 3 0 24 13 4 0 0 0 17 0 0 0 0 0 25 0 21 12 15 0

  11. #26
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Code:
    Node count: 495701
    
    real	0m49.295s
    user	0m48.615s
    sys	0m0.404s
    Apparently my friend got a sub-second implementation already...

    must... optimize...

  12. #27
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Heh. Well, my implementation so far can only solve simple 9x9 fields. I need to implement more solution strategies.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #28
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by cyberfish View Post
    Code:
    Node count: 668
    
    real	0m0.022s
    user	0m0.012s
    sys	0m0.004s
    (for the "difficult" 16x16 puzzle).
    That's pretty good!
    Mine solved the 16x16 one in 123 milliseconds on my ageing PC. Clearly still room for more optimisation.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sudoku 4 by 4 combination lister?
    By iskate4 in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2009, 01:56 PM
  2. sudoku - arrays
    By rocketman50 in forum C++ Programming
    Replies: 2
    Last Post: 03-21-2008, 09:20 AM
  3. sudoku program
    By ElemenT.usha in forum C Programming
    Replies: 1
    Last Post: 02-12-2008, 12:51 PM
  4. Help for a sudoku Solver
    By axilleask in forum C Programming
    Replies: 3
    Last Post: 11-26-2007, 04:28 PM
  5. Sudoku - the new addiction
    By axon in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-07-2005, 11:39 PM