<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://pierre.lacave.me/index.php?feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>FreakyZoidberg - SGDB</title>
  <link>http://pierre.lacave.me/index.php?</link>
  <atom:link href="http://pierre.lacave.me/index.php?feed/category/SGDB/rss2" rel="self" type="application/rss+xml"/>
  <description></description>
  <language>en</language>
  <pubDate>Sat, 04 Sep 2010 08:00:26 +0100</pubDate>
  <copyright></copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Solve Sudoku using SQL</title>
    <link>http://pierre.lacave.me/index.php?post/2009/11/01/Solve-Sudoku-using-SQL</link>
    <guid isPermaLink="false">urn:md5:c0ddcf57ed81df13c39a94e700f0b2e7</guid>
    <pubDate>Sun, 01 Nov 2009 22:01:00 +0000</pubDate>
    <dc:creator>Pierre Lacave</dc:creator>
        <category>SGDB</category>
            
    <description>    &lt;p&gt;Say we have a sudoku like this:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://pierre.lacave.me/public/250px-sudoku-by-l2g-20050714_svg.png&quot; alt=&quot;250px-sudoku-by-l2g-20050714_svg.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;250px-sudoku-by-l2g-20050714_svg.png, nov. 2009&quot; /&gt;
first you need to put all the number as if they were in a signle row&amp;nbsp;:&lt;/p&gt;


&lt;p&gt;&quot;53  7    6  195    98    6 8   6   34  8 3  17   2   6 6    28    419  5    8  79&quot;&lt;/p&gt;


&lt;p&gt;then use with Oracle the following query (recursive subquery)&lt;/p&gt;



&lt;pre&gt;with x( s, ind ) as
( select sud, instr( sud, ' ' )
 from ( select '53  7    6  195    98    6 8   6   34  8 3  17   2   6 6    28    419  5    8  79' sud from dual )
  union all
  select substr( s, 1, ind - 1 ) || z || substr( s, ind + 1 )
       , instr( s, ' ', ind + 1 )
  from x
     , ( select to_char( rownum ) z
         from dual
         connect by rownum &amp;lt;= 9
       ) z
  where ind &amp;gt; 0
  and not exists ( select null
                   from ( select rownum lp
                          from dual
                          connect by rownum &amp;lt;= 9
                        )
                   where z = substr( s, trunc( ( ind - 1 ) / 9 ) * 9 + lp, 1 )
                   or    z = substr( s, mod( ind - 1, 9 ) - 8 + lp * 9, 1 )
                   or    z = substr( s, mod( trunc( ( ind - 1 ) / 3 ), 3 ) * 3
                                      + trunc( ( ind - 1 ) / 27 ) * 27 + lp
                                      + trunc( ( lp - 1 ) / 3 ) * 6
                                   , 1 )
                 )
)
select s
from x
where ind = 0
/&lt;/pre&gt;


&lt;p&gt;&lt;img src=&quot;http://pierre.lacave.me/public/250px-sudoku-by-l2g-20050714_solution_svg.png&quot; alt=&quot;250px-sudoku-by-l2g-20050714_solution_svg.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;250px-sudoku-by-l2g-20050714_solution_svg.png, nov. 2009&quot; /&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://pierre.lacave.me/index.php?post/2009/11/01/Solve-Sudoku-using-SQL#comment-form</comments>
      <wfw:comment>http://pierre.lacave.me/index.php?post/2009/11/01/Solve-Sudoku-using-SQL#comment-form</wfw:comment>
      <wfw:commentRss>http://pierre.lacave.me/index.php?feed/atom/comments/10</wfw:commentRss>
      </item>
    
</channel>
</rss>