<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Juozas devBlog &#187; combinations</title>
	<atom:link href="http://dev.juokaz.com/tag/combinations/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.juokaz.com</link>
	<description>Random ideas, scripts and facts</description>
	<lastBuildDate>Mon, 22 Mar 2010 10:48:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Solving Sudoku puzzle with only MySQL</title>
		<link>http://dev.juokaz.com/mysql/solving-soduku-with-only-mysql</link>
		<comments>http://dev.juokaz.com/mysql/solving-soduku-with-only-mysql#comments</comments>
		<pubDate>Wed, 11 Feb 2009 15:35:45 +0000</pubDate>
		<dc:creator>Juozas</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[combinations]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[geeks]]></category>
		<category><![CDATA[lamneth]]></category>
		<category><![CDATA[positions]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[solver]]></category>
		<category><![CDATA[sudoku]]></category>

		<guid isPermaLink="false">http://dev.juokaz.com/?p=84</guid>
		<description><![CDATA[More than a year ago I&#8217;ve read very interesting article in Lamneth blog about MySQL Sudoku solver. I&#8217;ve searched for some time, but information was very minimal and I couldn&#8217;t find a way to contact original author. So I decided to try it myself and easily found working solution.
Beauty of solving Sudoku puzzle in MySQL [...]]]></description>
			<content:encoded><![CDATA[<p>More than a year ago I&#8217;ve read very interesting <a href="http://lamneth.wordpress.com/2007/07/26/can-you-solve-a-sudoku-puzzle-faster-than-this/">article</a> in Lamneth blog about MySQL Sudoku solver. I&#8217;ve searched for some time, but information was very minimal and I couldn&#8217;t find a way to contact original author. So I decided to try it myself and easily found working solution.</p>
<p>Beauty of solving Sudoku puzzle in MySQL is that you don&#8217;t need any server-side code (almost) at all. Only thing you need to do is to form a query and then pass it to MySQL server. Tasks list for 9&#215;9 Sudoku puzzle would like this:</p>
<ol>
<li>Table will all possible combinations (362880, 9*8*7*6*5*4*3*2*1)</li>
<li>Query to:
<ul>
<li>join combinations table 9 times</li>
<li>set already known cell values</li>
<li>get results</li>
</ul>
</li>
</ol>
<p>It may seem not very clear, but it&#8217;s very trivial method. <em>Positions</em> table holds all possible combinations, so you select 9 rows from this table, where each cell is unique in row and column and some predefined cells equal to given values. Basically, you tell MySQL <a href="http://www.sudoku.name/rules/en">Sudoku rules</a> and MySQL does all work for you.</p>
<p style="text-align: center;"><img class="size-full wp-image-91 aligncenter" style="margin-right: 40px;" title="Solving" src="http://dev.juokaz.com/wp-content/uploads/2009/02/solving.png" alt="Solving" width="459" height="345" /></p>
<p>I&#8217;ve published sample query and positions table data online here: <a href="http://dev.juokaz.com/examples/sudoku/query.sql.gz">positions</a>, <a href="http://dev.juokaz.com/examples/sudoku/run.sql">query</a>. Example will solve puzzle given in original Lamneth post (<a href="http://polly97.wordpress.com/2007/06/13/sudoku/">here</a>) and it shouldn&#8217;t take too long &#8211; in my laptop it takes about 0.7 s. I haven&#8217;t tried any optimizations, but I strongly believe that solving process can be optimized dramatically (especially for <em>hard</em> puzzles).</p>
<p>This method works pretty good &#8211; almost all puzzles are solved around 1 s., and only hard ones takes a while. Compared to real solvers it&#8217;s very slow, but since it&#8217;s only a simple query &#8211; results look very good.</p>
<p>MySQL is not made for games, but for fun you can make some nice applications (solving Sudoku with MySQL will not help you to get a better job). How much faster you can make this query run?</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.juokaz.com/mysql/solving-soduku-with-only-mysql/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
