From: | Andrej <andrej(dot)groups(at)gmail(dot)com> |
---|---|
To: | Richard Broersma <richard(dot)broersma(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: sudoku in an sql statement |
Date: | 2009-11-04 23:38:04 |
Message-ID: | b35603930911041538y705bda73j3ca57583c0ca770a@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
2009/11/5 Richard Broersma <richard(dot)broersma(at)gmail(dot)com>:
> On Wed, Nov 4, 2009 at 3:18 PM, marcin mank <marcin(dot)mank(at)gmail(dot)com> 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.
From | Date | Subject | |
---|---|---|---|
Next Message | marcin mank | 2009-11-04 23:39:52 | Re: sudoku in an sql statement |
Previous Message | Richard Broersma | 2009-11-04 23:31:09 | Re: sudoku in an sql statement |