Search Postgresql Archives

Re: sudoku in an sql statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/11/5 Richard Broersma <richard.broersma@xxxxxxxxx>:
> On Wed, Nov 4, 2009 at 3:18 PM, marcin mank <marcin.mank@xxxxxxxxx> wrote:
>> -----------------------------------------------------------------------------------
>>  534678912672195348198342567859761423426853791713924856961537284287419635345286179
>> (1 row)

> broersr=> with recursive x( s, ind ) as
> broersr-> ( select sud, position( ' ' in sud )
> broersr(>  from  (select '53  7    6  195    98    6 8   6   34  8 3  17   2
> broersr'> 6 6    28    419  5    8  79'::text as sud) xx

Get rid of that line-wrap - it screwed up the spacing.


> broersr(>  union all
> broersr(>  select substr( s, 1, ind - 1 ) || z || substr( s, ind + 1 )
> broersr(>       , position(' ' in repeat('x',ind) || substr( s, ind + 1 ) )
> broersr(>  from x
> broersr(>     ,  (select gs::text as z from generate_series(1,9) gs)z
> broersr(>  where ind > 0
> broersr(>  and not exists ( select null
> broersr(>                   from generate_series(1,9) lp
> broersr(>                   where z.z = substr( s, ( (ind - 1 ) / 9 )
> * 9 + lp, 1 )
> broersr(>                   or    z.z = substr( s, mod( ind - 1, 9 ) -
> 8 + lp * 9, 1 )
> broersr(>                   or    z.z = substr( s, mod( ( ( ind - 1 )
> / 3 ), 3 ) * 3
> broersr(>                                      + ( ( ind - 1 ) / 27 ) * 27 + lp
> broersr(>                                      + ( ( lp - 1 ) / 3 ) * 6
> broersr(>                                   , 1 )
> broersr(>                 )
> broersr(> )
> broersr-> select s
> broersr-> from x
> broersr-> where ind = 0;
>  s
> ---
> (0 rows)

Cheers,
Andrej

-- 
Please don't top post, and don't use HTML e-Mail :}  Make your quotes concise.

http://www.american.edu/econ/notes/htmlmail.htm

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux