some OT: how to solve this kind of problem in our program?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Dec 24 04:45:44 EST 2006


In <mailman.1995.1166935152.32031.python-list at python.org>, oyster wrote:

> 1. first of all, what is the English jargon (Optimize? But I think
> this is not a very good keyword :( )for this problem? So I can use it
> to search on the internet
> 2. is there any free/open lib for this?
> 3. I know for some questions(case 1, case 2, and sudoku), we can use
> bundles of "FOR...NEXT" loop to program. however I think it is clumsy
> and inconvenient, especially when there is many vars
> 4. I don't know how to deal with case 3 and case 4
> 
> 
> case:
> 1. choose x0~x9 from 1~9, and must use all of 1~9, let
> x0/(10*x1+x2)+x3/(10*x4+x5)+x6/(10*x7+x8)=1/2
> 
> 2. choose x0~x15 from 1~16, and must use all of 1~16, let
> +-----+-----+-----+-----+
> |  x0 |  x1 |  x2 |  x3 |
> +-----+-----+-----+-----+
> |  x4 |  x5 |  x6 |  x7 |
> +-----+-----+-----+-----+
> |  x8 |  x9 | x10 | x11 |
> +-----+-----+-----+-----+
> | x12 | x13 | x14 | x15 |
> +-----+-----+-----+-----+
> 
> sum of every column =sum of of every row
> = x0+x5+x10+x11 =x3+x6+x9+x12

The first two can be solved by a finite domain constraint solver.  Logilab
has a pure-python package:

http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%20852

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list