<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Solving sudoku using PostgreSQL PL/pgSQL</title>
	<atom:link href="http://www.microshell.com/database/postgresql/solving-sudoku-using-postgresql-plpgsql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.microshell.com/database/postgresql/solving-sudoku-using-postgresql-plpgsql/</link>
	<description>Learn something share something</description>
	<lastBuildDate>Mon, 23 Jan 2012 10:40:22 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: WildWezyr</title>
		<link>http://www.microshell.com/database/postgresql/solving-sudoku-using-postgresql-plpgsql/comment-page-1/#comment-3197</link>
		<dc:creator>WildWezyr</dc:creator>
		<pubDate>Thu, 18 Mar 2010 11:19:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=1197#comment-3197</guid>
		<description>@Maresa: additional pl/pgsql language constructs may lead to shorter solutions, but not that huge difference in terms of efficiency. you could do the same algorithm as with &quot;WITH RECURSIVE&quot; using plain old postgres functions and it should work aproximately as good as single query or even better.</description>
		<content:encoded><![CDATA[<p>@Maresa: additional pl/pgsql language constructs may lead to shorter solutions, but not that huge difference in terms of efficiency. you could do the same algorithm as with &#8220;WITH RECURSIVE&#8221; using plain old postgres functions and it should work aproximately as good as single query or even better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maresa</title>
		<link>http://www.microshell.com/database/postgresql/solving-sudoku-using-postgresql-plpgsql/comment-page-1/#comment-3171</link>
		<dc:creator>Maresa</dc:creator>
		<pubDate>Mon, 15 Mar 2010 16:39:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=1197#comment-3171</guid>
		<description>Yeah .. it is actually very slow. The link that you sent uses the new WITH RECURSIVE support of PostgreSQL 8.4 which was released after my posting.</description>
		<content:encoded><![CDATA[<p>Yeah .. it is actually very slow. The link that you sent uses the new WITH RECURSIVE support of PostgreSQL 8.4 which was released after my posting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WildWezyr</title>
		<link>http://www.microshell.com/database/postgresql/solving-sudoku-using-postgresql-plpgsql/comment-page-1/#comment-3162</link>
		<dc:creator>WildWezyr</dc:creator>
		<pubDate>Sun, 14 Mar 2010 12:33:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=1197#comment-3162</guid>
		<description>This is my second comment (first is still awaiting moderation): take a look at this: sudoku solver in just one select statement:

http://wiki.postgresql.org/wiki/Sudoku_puzzle

it is PostgreSQL select query and is quite fast - 120 seconds for Easter Monster compared to 4 seconds of my JavaScript solver and indeterminate amount of time of yours ;-).</description>
		<content:encoded><![CDATA[<p>This is my second comment (first is still awaiting moderation): take a look at this: sudoku solver in just one select statement:</p>
<p><a href="http://wiki.postgresql.org/wiki/Sudoku_puzzle" rel="nofollow">http://wiki.postgresql.org/wiki/Sudoku_puzzle</a></p>
<p>it is PostgreSQL select query and is quite fast &#8211; 120 seconds for Easter Monster compared to 4 seconds of my JavaScript solver and indeterminate amount of time of yours <img src='http://www.microshell.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: WildWezyr</title>
		<link>http://www.microshell.com/database/postgresql/solving-sudoku-using-postgresql-plpgsql/comment-page-1/#comment-3160</link>
		<dc:creator>WildWezyr</dc:creator>
		<pubDate>Sat, 13 Mar 2010 23:00:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=1197#comment-3160</guid>
		<description>It seems that your solution is very slow. I\&#039;ve executed it to find solution for Easter Monster and it is now running for over 2 660 seconds with no result :-(.

For comparison: my old JavaScript solution yields result after 4 seconds on Chrome 4. Look could at it here: http://wildwezyr-sudoku-solver.blogspot.com/

To facilitate population of sudoku table before execution of your code, I use this function:

CREATE OR  REPLACE FUNCTION  func_full_solve_sudoku(input_data text)
  RETURNS varchar(81) as
$BODY$DECLARE
  x int;
  y int;
  inp varchar(81);
  d int;
  c varchar(1);
BEGIN
  inp := regexp_replace(regexp_replace(input_data, \&#039;[\\n\\r]\&#039;, \&#039;\&#039;, \&#039;g\&#039;), \&#039;[^1-9]\&#039;, \&#039; \&#039;, \&#039;g\&#039;);

  truncate table sudoku;
  
  for y in 0..8 loop
    for x in 0..8 loop      
      d := null;
      c := substring(inp, y * 9 + x + 1, 1);
      if c is not null and length(c) = 1 and c &lt;&gt; \&#039; \&#039; then d := cast(c as int); end if;
      if d is not null then
	insert into sudoku (x_col, y_col, val, is_permanent) values (y + 1, x + 1, d, true);
      end if;
    end loop;
  end loop;    

  perform func_solve_sudoku();

  inp := \&#039;\&#039;;
  
  for y in 0..8 loop
    for x in 0..8 loop      
      select cast(val as varchar(1)) into c from sudoku where x_col = y + 1 and y_col = x + 1;
      inp := inp &#124;&#124; coalesce(c, \&#039;?\&#039;);
    end loop;
  end loop;    
  

  return inp;
END;$BODY$
  LANGUAGE \&#039;plpgsql\&#039; VOLATILE;

Then for Easter Monster I just run:

select func_full_solve_sudoku(\&#039;1.......2.9.4...5...6...7...5.9.3.......7.......85..4.7.....6...3...9.8...2.....1\&#039;)

If you want to see how is my solution performing for this puzzle, use this matrix

1.......2
.9.4...5.
..6...7..
.5.9.3...
....7....
...85..4.
7.....6..
.3...9.8.
..2.....1

in textarea on the left and click [import-&gt;] and then [solve].</description>
		<content:encoded><![CDATA[<p>It seems that your solution is very slow. I\&#8217;ve executed it to find solution for Easter Monster and it is now running for over 2 660 seconds with no result <img src='http://www.microshell.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> .</p>
<p>For comparison: my old JavaScript solution yields result after 4 seconds on Chrome 4. Look could at it here: <a href="http://wildwezyr-sudoku-solver.blogspot.com/" rel="nofollow">http://wildwezyr-sudoku-solver.blogspot.com/</a></p>
<p>To facilitate population of sudoku table before execution of your code, I use this function:</p>
<p>CREATE OR  REPLACE FUNCTION  func_full_solve_sudoku(input_data text)<br />
  RETURNS varchar(81) as<br />
$BODY$DECLARE<br />
  x int;<br />
  y int;<br />
  inp varchar(81);<br />
  d int;<br />
  c varchar(1);<br />
BEGIN<br />
  inp := regexp_replace(regexp_replace(input_data, \&#8217;[\\n\\r]\&#8217;, \&#8217;\', \&#8217;g\&#8217;), \&#8217;[^1-9]\&#8217;, \&#8217; \&#8217;, \&#8217;g\&#8217;);</p>
<p>  truncate table sudoku;</p>
<p>  for y in 0..8 loop<br />
    for x in 0..8 loop<br />
      d := null;<br />
      c := substring(inp, y * 9 + x + 1, 1);<br />
      if c is not null and length(c) = 1 and c &lt;&gt; \&#8217; \&#8217; then d := cast(c as int); end if;<br />
      if d is not null then<br />
	insert into sudoku (x_col, y_col, val, is_permanent) values (y + 1, x + 1, d, true);<br />
      end if;<br />
    end loop;<br />
  end loop;    </p>
<p>  perform func_solve_sudoku();</p>
<p>  inp := \&#8217;\';</p>
<p>  for y in 0..8 loop<br />
    for x in 0..8 loop<br />
      select cast(val as varchar(1)) into c from sudoku where x_col = y + 1 and y_col = x + 1;<br />
      inp := inp || coalesce(c, \&#8217;?\&#8217;);<br />
    end loop;<br />
  end loop;    </p>
<p>  return inp;<br />
END;$BODY$<br />
  LANGUAGE \&#8217;plpgsql\&#8217; VOLATILE;</p>
<p>Then for Easter Monster I just run:</p>
<p>select func_full_solve_sudoku(\&#8217;1&#8230;&#8230;.2.9.4&#8230;5&#8230;6&#8230;7&#8230;5.9.3&#8230;&#8230;.7&#8230;&#8230;.85..4.7&#8230;..6&#8230;3&#8230;9.8&#8230;2&#8230;..1\&#8217;)</p>
<p>If you want to see how is my solution performing for this puzzle, use this matrix</p>
<p>1&#8230;&#8230;.2<br />
.9.4&#8230;5.<br />
..6&#8230;7..<br />
.5.9.3&#8230;<br />
&#8230;.7&#8230;.<br />
&#8230;85..4.<br />
7&#8230;..6..<br />
.3&#8230;9.8.<br />
..2&#8230;..1</p>
<p>in textarea on the left and click [import-&gt;] and then [solve].</p>
]]></content:encoded>
	</item>
</channel>
</rss>

