Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Puzzle Games (Games) Debian It's funny.  Laugh. Math

Solving Sudoku With dpkg 190

Reader Otter points out in his journal a very neat use for the logic contained in Debian's package dependency resolver: solving sudoku puzzles. To me at least, this is much more interesting than the sudoku puzzles themselves. Update: 08/24 02:51 GMT by T : Hackaday just ran a story that might tickle the same parts of your brain on a game played entirely with MySQL database queries.
This discussion has been archived. No new comments can be posted.

Solving Sudoku With dpkg

Comments Filter:
  • by Anonymous Coward on Saturday August 23, 2008 @10:52PM (#24723609)

    Jesus Christ. If you're going to mention the greatest cheat code ever, get it right:
    Up-Up-Down-Down-Left-Right-Left-Right-B-A-(Select)-(Start)

    Amateur.

  • by Asuranceturix ( 1265166 ) on Saturday August 23, 2008 @11:17PM (#24723717)

    And he didn't even use Super Cow Powers to do it!

  • by _xeno_ ( 155264 ) on Saturday August 23, 2008 @11:19PM (#24723727) Homepage Journal

    RTFA. I know, I know, what am I suggesting, it's Slashdot.

    Here's the quick version: Russell Coker remarked [coker.com.au] that "a package management system that can solve Sudoku based on package dependency rules is not something that I think would be useful or worth having."

    Daniel Burrows realized that apt could, in fact, currently be used to solve Sudoku puzzles [algebraicthunk.net], and wrote a Python script to automate the process of creating the packages required to do such a thing. That's the linked article, and it gives the background I'm repeating here.

    I, personally, think it's pretty damned cool. Useless, but cool.

    And, as the article points out, there exist better Sudoku solving algorithms. apt is a rather poor Sudoku solver, mainly because it's designed to come up with the "best" dependency resolution rather than solve Sudoku. It's not to "cheat" at Sudoku, but rather to demonstrate the power of the apt dependency resolver.

  • by Nymz ( 905908 ) on Saturday August 23, 2008 @11:31PM (#24723775) Journal

    Sudoku doesn't have clever logic and elegant methods.

    Check out the various strategies listed on this Sudoku Solver. [scanraid.com]

    Don't mod me down if you disagree. If you disagree, consider writing a retort instead.

    You must be new here. Only posters that take the time to back up conclusions with reasoned responses are moderated down. Conversely, those that write short, unsupported attacks are moderated up... because in reality most people can only be trusted with 2 tags - I agree or I disagree.

  • Re:Splitting Hairs (Score:3, Informative)

    by maxume ( 22995 ) on Saturday August 23, 2008 @11:42PM (#24723845)

    The "Propagating Constraints" section of this article is quite a bit less brute force than the "search" section:

    http://norvig.com/sudoku.html [norvig.com]

  • by tukang ( 1209392 ) on Saturday August 23, 2008 @11:53PM (#24723891)

    Sudoku isn't a math puzzle, it's a logic puzzle - just one where you're filling in digits instead of the man in the blue house smoking Pall Malls and having a goldfish.

    The digits 1-9 in Sudoku could be replaced with any 9 other symbols without changing the underlying rules. So yeah, logic can be used to solve it.

    How did this get modded insightful? Just because numbers don't have to be used doesn't mean it's not math.

    Sudoku is a set theory [wikipedia.org] problem

  • by DMUTPeregrine ( 612791 ) on Sunday August 24, 2008 @04:01AM (#24724717) Journal
    That's the 2-player code.
    Up-Up-Down-Down-Left-Right-Left-Right-A-B-(Start) is single player contra.
  • by jonaskoelker ( 922170 ) <jonaskoelkerNO@SPAMyahoo.com> on Sunday August 24, 2008 @05:08AM (#24724949)

    Allow me to clarify parent and grand-parent for those of you who don't read articles:

    As a proof-of-concept, I have written a hacky Python script, named debsudoku.py, that can convert ksudoku saved games into Packages files suitable for use with apt-get or aptitude.

    (Source: TFA, at http://algebraicthunk.net/~dburrows/blog/entry/package-management-sudoku/ [algebraicthunk.net])

    Emphasis added. Note that dpkg doesn't solve the dependency puzzle, but apt-get, aptitude and other package managers do (including synaptic and gnome-app-install [the "Add/Remove" thing]). Hence the suggested badtitle (which I agree with).

    The 'aptitude --help' bit and the super cow powers: if you run 'apt-get moo', you'll get a cowsay output (that is, an ascii-art cow saying "Have you mooed today"). Running 'aptitude moo' gets you "There are no Easter Eggs in this program". Running 'apt$GETITUDE --help' gives you "this apt[itude] does [not] have Super Cow Powers".

    Just FYI ;)

  • by FireFlie ( 850716 ) on Sunday August 24, 2008 @09:53AM (#24725867)
    Perhaps I'm misunderstanding you, but your method will still require a validity check. Many swaps will result in illegal puzzles. For instance, swap any two numbers on the same row or column.
  • by AySz88 ( 1151141 ) on Sunday August 24, 2008 @02:11PM (#24727717)

    Sudoku, in the way that it's being solved here and how most people think of it (with 9 digits and 3x3 boxes), is not NP-complete. Its board size is finite, so there are a bounded number of possibilities to try (fewer than (9!)^9), so there exists a constant-time algorithm (trying every one of the possibilities, of which there must be less than 9!^9). But if you want to generalize to nxn boards, that changes things considerably.

  • by asc99c ( 938635 ) on Sunday August 24, 2008 @06:46PM (#24730519)

    It's very rare that I have found the need to guess in a Sudoku. I've never seen a printed one in a newspaper where that was necessary - even the 'diabolical' ones.

    Certainly I've made mistakes on some, and a couple of times I've run out of ideas and had to make a guess, but on running it through my own program, it's got the solution without taking guesses.

    There is a good online solver at http://www.sudokusolver.co.uk/ [sudokusolver.co.uk] that explains how it solves any Sudoku that you enter. This has a couple more methods to try than my own solver program, but a lot less than some. I've seen all kinds of complicated algorithms, but I think many of them are never required if you've properly applied the simpler ones.

    For a real challenge, this page has a number of grids that couldn't be solved using a proper algorithm (other than guess and check):
    http://www.sudokusolver.co.uk/grids_nologic.html [sudokusolver.co.uk]

"A car is just a big purse on wheels." -- Johanna Reynolds

Working...