From: drh Date: Sat, 18 Jan 2014 18:33:44 +0000 (+0000) Subject: Add a sudoku solver to the recursive query tests in with1.test. X-Git-Tag: version-3.8.3~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=717c09c4a94406e27148dc75f18afd02e023b845;p=thirdparty%2Fsqlite.git Add a sudoku solver to the recursive query tests in with1.test. FossilOrigin-Name: 679eff8759aa25368b977c0d26b78a9fcd9486f5 --- diff --git a/manifest b/manifest index 522f30a10d..7463d67494 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sextra\stest\scases.\sNo\schanges\sto\scode. -D 2014-01-18T15:59:35.958 +C Add\sa\ssudoku\ssolver\sto\sthe\srecursive\squery\stests\sin\swith1.test. +D 2014-01-18T18:33:44.994 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1091,7 +1091,7 @@ F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c F test/win32heap.test ea19770974795cff26e11575e12d422dbd16893c F test/win32lock.test 7a6bd73a5dcdee39b5bb93e92395e1773a194361 F test/win32longpath.test 169c75a3b2e43481f4a62122510210c67b08f26d -F test/with1.test be21f7efdc08fe6ad182dc943d42704300f0fcdb +F test/with1.test cec63b56797a70842afa8929c241dfdb3d864283 F test/with2.test 67a3347f2d78618db9434a248fb5003af8f04bc1 F test/withM.test e97f2a8c506ab3ea9eab94e6f6072f6cc924c991 F test/without_rowid1.test aaa26da19d543cd8d3d2d0e686dfa255556c15c8 @@ -1151,7 +1151,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 2ad4583c0cc7988f0dfe78fd0a2eb0fdb92d835a -R 71fcd9d8c24b81a08237ce7106794f40 -U dan -Z 1a2b2ad5eb21bdc784c4eae4f3f812b5 +P d38d485e581dab99a3ee6b348da8ddaf9b379ff2 +R 65511deacff317a7a6d96d8a97a06cc3 +U drh +Z 1781cdebe197572ff0a729675feb42d9 diff --git a/manifest.uuid b/manifest.uuid index e5d4cbf4df..8e6cce16db 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d38d485e581dab99a3ee6b348da8ddaf9b379ff2 \ No newline at end of file +679eff8759aa25368b977c0d26b78a9fcd9486f5 \ No newline at end of file diff --git a/test/with1.test b/test/with1.test index 54e0f0aa91..fcf59267f2 100644 --- a/test/with1.test +++ b/test/with1.test @@ -367,4 +367,41 @@ do_execsql_test 8.1 { ....# +.}} +# Solve a sudoku puzzle using a recursive query +# +do_execsql_test 8.2 { + WITH RECURSIVE + input(sud) AS ( + VALUES('53..7....6..195....98....6.8...6...34..8.3..17...2...6.6....28....419..5....8..79') + ), + + /* A table filled with digits 1..9, inclusive. */ + digits(z, lp) AS ( + VALUES('1', 1) + UNION ALL SELECT + CAST(lp+1 AS TEXT), lp+1 FROM digits WHERE lp<9 + ), + + /* The tricky bit. */ + x(s, ind) AS ( + SELECT sud, instr(sud, '.') FROM input + UNION ALL + SELECT + substr(s, 1, ind-1) || z || substr(s, ind+1), + instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' ) + FROM x, digits AS z + WHERE ind>0 + AND NOT EXISTS ( + SELECT 1 + FROM digits AS lp + WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1) + OR z.z = substr(s, ((ind-1)%9) + (lp-1)*9 + 1, 1) + OR z.z = substr(s, (((ind-1)/3) % 3) * 3 + + ((ind-1)/27) * 27 + lp + + ((lp-1) / 3) * 6, 1) + ) + ) + SELECT s FROM x WHERE ind=0; +} {534678912672195348198342567859761423426853791713924856961537284287419635345286179} + finish_test