## Solving Sudoku With dpkg 190

Posted
by
timothy

from the after-all-it's-there dept.

from the after-all-it's-there dept.

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.
## Well, it's ultimately a logic puzzle. (Score:5, Insightful)

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.

## Re:Cheat code for even Sudoku?? (Score:5, Insightful)

First, it's not "cheat codes".

Second, I, and I'm sure I'm not alone on this, would rather write a program to solve sudoku than actually play sudoku. Some people love sudoku; I found it boring. Now writing software to solve a puzzle, that's interesting.

## Re:Splitting Hairs (Score:1, Insightful)

are fairly boring when compared to clever logic with elegant methods, that can solve sudokus in a fraction of time.

Sudoku doesn't have clever logic and elegant methods. There is only one method for solving sudoku puzzles, and it strongly resembles a computer doing brute force.

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

## Re:Cheat code for even Sudoku?? (Score:5, Insightful)

It isn't about beating sudoku. It's about taking one tool, and using it to do something that its creators never imagined.

It's the same reason people use laser cutters to slice their pizza or try to create the shortest possible quine in their language of choice. This guy might not even give a shit about sudoku; he just wanted to see if he was clever enough to solve sudoku using dpkg.

## Re:Cheat code for even Sudoku?? (Score:5, Insightful)

Exactly. This guy doesn't care about the sudoku puzzle, he cares about the programming puzzle.

## Elegant methods (Score:5, Insightful)

Sudoku doesn't have clever logic and elegant methods. There is only one method for solving sudoku puzzles, and it strongly resembles a computer doing brute force.

Sure, there are brute force methods. They are often techniques that dive into deep "consequence" trees to find contradictions. Those are, by their very nature, annoying for people to do and thus attractive for computer solutions. Nishio, tables, all of those just make sudoko boring and feel like you're executing a computer program in your limited-RAM brain.

But those aren't the "clever" or "elegant" methods. Sudoku techniques that I would consider elegant are things like sashimi x-wings, XYZ-wings, the various type of unique rectangles, and such. I enjoy trying to discover patterns like these in really tricky sudoku problems. I expect I'm not the only one, given the popularity of the puzzle over the last few years.

If you want to get really deep, you can use sudoku puzzles to explore mathematical group theory.

All of this (and what you said in your post) are true for other puzzles such as the Rubik's cube. Perfectly suitable for machine automation, but still fun for some of us us lowly humans as well.

## Brute force? (Score:3, Insightful)

Ultimately this approach simply encodes the rules of sudoku, and the state of an unsolved sudoku puzzle in logic statements, and then passes it off to a reasonably general logic solver, namely the dependency/conflict resolver in apt-get/aptitude. That's not really brute force at all.

Whether or not the solution is "brute force" depends on the manner in which debian's dependency/conflict resolver operates. There's many approaches to solving this problem, from gross brute force to reasonably complex machine learning approaches.

The insight in this approach (although it's not an especially new insight to people playing with this sort of idea), is the relationship between puzzles and other day-to-day computing problems purely as constraint satisfaction problems, which essentially means that we describe the problem abstractly without all the trappings of how humans interpret the problem, and let a computer with little to no "general purpose" knowledge or "common sense" come up with the solution on its own (and of course, of us being able to read out the solution once the computer nails it)

## Software used for weird purposes? (Score:5, Insightful)

## Re:Cheat code for even Sudoku?? (Score:4, Insightful)

It's probably less costly totake a square away at a time and check to see if it's still solvablethan to populate a random start and see if it's possible to solve it. And probably less complicated as well.Isn't that pretty much exactly what I said? Create a random valid

solvedpuzzle, then start removing squares...## Re:Well, it's ultimately a logic puzzle. (Score:3, Insightful)

Keeps your logic skills sharp. It's good mental exercise, in the vein of Brain Age and such... Gotta keep that noggin fit, especially if your day job isn't challenging you enough.

## Dpkg in NP hard?! (Score:3, Insightful)

Since Sudoku is NP complete, doesn't this mean Dpkg is NP complete?!

Oh, the humanity! I'm just waiting for an evil set of dependencies to crop up that makes it go exponential.

## Re:Well, it's ultimately a logic puzzle. (Score:4, Insightful)

Actually, Sudoku is a http://en.wikipedia.org/wiki/Vertex_coloring [wikipedia.org] for a special graph. From mathematics perspective, it is thus pretty boring, although that doesn't mean it cannot be fun.

## Re:I Disagree and I Agree (Score:2, Insightful)

You're doing it wrong. You're going to get yourself in a mess if you take random guesses in sudoku. Getting the full value of the brain exercise is the act of reducing the clues to a single number for a particular square all in your head. Of course, with the hard ones unless your brain is awesome you get a stack overflow before you can piece together enough clues to narrow a square down to one number, but your average puzzle in the 'paper is quite reasonably solved in a progression of logically chosen steps.

## Re:Splitting Hairs (Score:3, Insightful)

However, I do not believe that the grandparent is correct in stating that these methods solve sudokus in a fraction of the time of the brute force method if you allow for [...]

Well, run some tests then ;) Seriously, though: as you point out yourself, if you add some simple heuristics to the brute-forcing it ceases being brute-force. Guess what, the heuristics for solving Sudoku problems (you've pointed one out yourself) eventually run out, and you have to guess and backtrack or brute-force in some other way.

If we compare the completely vanilla brute force (that's 9^(n^2) tries where n^2 is the number of squares) with the heuristics-plus-brute-force, you may get something better than a constant factor time improvement (that is, time is reduced with more than just a fixed fraction). However, the Sudoku problem (for arbitrary-sized boards) is NP-complete, so you can't get down to polynomial time.

Although typical Sudoku puzzles (with 9×9 grid and 3×3 regions) can be solved quickly by computer, the generalization to larger grids is known to be NP-complete. Various optimization methods have been proposed for large grids.

(Source: http://en.wikipedia.org/wiki/Sudoku [wikipedia.org])

## Practice Makes Perfect (Score:3, Insightful)

I guess I'm just annoyed by these people who think that they are thinking, and am trying to burst their bubble.

I already learned all the chords on the guitar,

bubble. :-)

--and I'm just annoyed by these people who think that practicing will make me any better.

I already learned how to swim,

--and I'm just annoyed by these people who think that practicing will help me win an Olympic Medal.

Steven Hawking was simply born as a fully formed genius,

--and I'm just annoyed by these people who think that his thinking everyday has helped him achieve anything... but bursting

your## Re:Uh-oh (Score:2, Insightful)

But you

cancount anything you want in English, as long as the context is clear. If you treat the noun as countable, it's countable.I'll take four milks and three beefs.