Try integrating it with a user interface like this example: http://www.vantasyworld.com/fun/sudoku/sudokusolver.html.

Does it also detect sudoku puzzles that are impossible to solve?

]]>http://vbaexcel.eu/vba-macro-code/sudoku-solver

This solver I have been using works fine but it is alot of code compared to yours!

]]>-Mark

]]>I assume I need the first part, select from dual, then the model clause (model reference xxx on …. dimension by (i,j) measures (r), then followed by the “main solve” clause?

I keep getting syntax errors trying to run it, in 10.2.0.3.

-Mark

]]>http://www.devx.com/dbzone/Article/33551

FULL DISCLOSURE: That guy happens to be my dad 😉

]]>

By the way – if you like sql pluzzles you might like to try this, which can be solved by a single sql statement ( it will work even with Oracle 8i) , assuming you have a table called nums that holds the values 2..100.

I like this problem , since it is almost impossible to solve by hand. By the way, the answer is the same even if you make the largest value 1000 (and then solving by hand becomes a nightmare).

efine minval=2]]>

define maxval=100

set numwidth 6

set pages 0

set feedback off

set verify off

column a3 format a3

column a15 format a15

column num format 9999

prompt

prompt Solve the problem set by:

prompt

prompt There are 2 integers a and b between &&minval and &maxval, with a= a.num;

create view sums as select a+b s,count(*) cc

from pairs

group by a+b;

create view products as select a*b p,count(*) cc

from pairs

group by a*b;

prompt

prompt Paul: I don't know what the numbers are

prompt Sam : I knew that. I don't know what the numbers are either

prompt

prompt Paul's first statement is more helpful than it first appears

prompt The pair of numbers cannot be uniquely determined by their product

prompt This includes not just 2 primes such as 7 and 11,

prompt but also pairs like 19 and 38, or 4 and 53, 77 and 17

prompt (assuming we are only looking at 2 digit numbers)

prompt

prompt Sam's first statement is even more helpful.

prompt Sam knows that Paul can't possibly know the numbers

prompt So whatever his sum is, it cannot

prompt be formed by a pair that uniquely determines their product

prompt For example : the sum cannot be 18, or 57 or 94 using the above examples

prompt

prompt generate poss_sums as

prompt the only sums that cannot possibly be made by distinct product pairs

prompt There are surprisingly few

pause Ready?

create view poss_sums as

select s from sums where cc > 1

minus

select pairs.a+pairs.b s from pairs where pairs.a*pairs.b in

(select p from products where cc=1);

prompt

prompt From Sam's first statement the sum must be one of

prompt

select s from poss_sums

order by s;

prompt

prompt Paul's last statement:

prompt Paul: I do now!

prompt

prompt So Paul knows that Sam knew that he did not know the numbers and so

prompt must have a sum matching the above criterion

prompt This enables him to deduce the pairs.

prompt So Paul must have a product that decomposes to one of the sums

prompt in the above list

prompt in exactly one way (2 or more would not give him a solution and 0

prompt would violate Sam's previous statement)

prompt find all products that can have exactly one sum matching the list of sums above

prompt

pause Ready?

create view poss_prods as

select products.p,max(poss_sums.s) s

from products,pairs,poss_sums

where products.cc > 1

and pairs.a*pairs.b = products.p

and pairs.a+pairs.b = poss_sums.s

group by products.p

having count(poss_sums.s) = 1;

select 'product is ', p, 'sum is', s from poss_prods

order by p,s;

-- now find the sum that has only one possible product fitting that criterion

prompt

prompt Sam's last statement:

prompt Sam : So do I!

prompt

prompt So we need to find a sum that only occurs once in the above list

prompt Otherwise Sam could still not deduce the pair.

prompt and as we know both the product and the sum we can find the pair

prompt

pause Ready?

col plan_plus_exp for a120

set lines 160

select 'In the range' a15,min(num) num,'to' a3,max(num) num from nums;

set autotrace on explain

select 'The numbers are' a15, a num,'and' a3, b num

from pairs,

( select max(p) p,s from poss_prods group by s having count(*) = 1) pp

where pairs.a*pairs.b = pp.p

and pairs.a+pairs.b= pp.s

order by a,b;

set autotrace off

drop view poss_prods;

drop view poss_sums;

drop view products;

drop view sums;

drop view pairs;

prompt

prompt or to be perverse, and use only in-line views

pause Ready?

prompt

-- using the with clause is much too slow in 10.1

-- with nums as (select rownum+&&minval-1 num from sys.tab$

-- where rownum = a.num

) pairs,

( select max(p) p,s

from ( select products.p,max(poss_sums.s) s

from ( select a.num*b.num p,count(*) cc

from nums a, nums b

where b.num>= a.num

group by a.num*b.num

having count(*) > 1

) products,

( select a.num a, b.num b

from nums a, nums b

where b.num >= a.num

) prs,

(

select s

from ( select a.num+b.num s

from nums a, nums b

where b.num >= a.num

group by a.num+b.num

having count(*) > 1

) sums

minus

select prs2.a+prs2.b s

from ( select a.num a, b.num b

from nums a, nums b

where b.num >= a.num

) prs2

where prs2.a*prs2.b in

( select a.num*b.num p

from nums a, nums b

where b.num >= a.num

group by a.num*b.num

having count(*) = 1

)

) poss_sums

where prs.a*prs.b = products.p

and prs.a+prs.b = poss_sums.s

group by products.p

having count(poss_sums.s) = 1

)

group by s having count(*) = 1

) pp

where pairs.a*pairs.b = pp.p

and pairs.a+pairs.b= pp.s

order by a,b;

set autotrace off

set timing off

drop table nums;