From: | Richard Broersma <richard(dot)broersma(at)gmail(dot)com> |
---|---|
To: | marcin mank <marcin(dot)mank(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: sudoku in an sql statement |
Date: | 2009-11-04 23:31:09 |
Message-ID: | 396486430911041531r1596e2aek401766e7f55aabbb@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Nov 4, 2009 at 3:18 PM, marcin mank <marcin(dot)mank(at)gmail(dot)com> wrote:
> s
> -----------------------------------------------------------------------------------
> 534678912672195348198342567859761423426853791713924856961537284287419635345286179
> (1 row)
I don't get the same results:
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
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)
--
Regards,
Richard Broersma Jr.
Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug
From | Date | Subject | |
---|---|---|---|
Next Message | Andrej | 2009-11-04 23:38:04 | Re: sudoku in an sql statement |
Previous Message | Greg Stark | 2009-11-04 23:28:20 | Re: sudoku in an sql statement |