You would also want an additional constraint: n >= 0. Such problems form the
class of so called Integer Programming problems. These problems are NP-hard in
general, but there are good software (including open-source) available to
solve such problems.  e.g. https://projects.coin-or.org/Cbc

The above solver, Cbc, is available as an optional package for sage. See:
http://www.sagemath.org/packages/optional/
I haven't used it myself though.

Hope this helps.
--
regards
Ashutosh Mahajan
http://coral.ie.lehigh.edu/~asm4

On Wed, Feb 17, 2010 at 07:21:01PM -0600, Oscar Gerardo Lazo Arjona wrote:
> A friend of mine proposed me the following problem:
>
> A reporter asks a military officer how many soldiers are at a certain  
> military base. The officer, not wanting to reveal such sensitive  
> information, but also not wanting to seem overly secretive, gives an  
> indirect answer:
>
> When my soldiers form 2 collumns there is 1 soldier left.
> When my soldiers form 3 collumns there are 2 soldier left.
> When my soldiers form 4 collumns there are 3 soldier left.
> When my soldiers form 5 collumns there are 4 soldier left.
> When my soldiers form 6 collumns there are 5 soldier left.
> When my soldiers form 7 collumns there are 0 soldier left.
>
> How many soldiers are there?
>
> I formed the following equations system and put it on a notebook cell:
>
> var('x1 x2 x3 x4 x5 x6 n')
> eq1=7*x1    ==n
> eq2=6*x2 +5 ==n
> eq3=5*x3 +4 ==n
> eq4=4*x4 +3 ==n
> eq5=3*x5 +2 ==n
> eq6=2*x6 +1 ==n
> equations=(eq1,eq2,eq3,eq4,eq5,eq6)
> solve(equations,x2,x3,x4,x5,x6,n)
>
> And got:
>
> [[
> x2 == 7/6*x1 - 5/6,
> x3 == 7/5*x1 - 4/5,
> x4 == 7/4*x1 - 3/4,
> x5 ==7/3*x1 - 2/3,
> x6 == 7/2*x1 - 1/2,
> n == 7*x1]]
>
> Which is correct as far as I can see, but it only produces a valid n  
> when all of x1,x2,x3,x4,x5,x6 are integer.
>
> I know I could find the answer by examining succesive values of x1  
> untill all the x are integer, but is there some way to tell sage that we  
> are dealing with integer variables? I have the feeling that this is a  
> more profound problem than it appears (finding integer solutions).
>
> thanks!
>
> Oscar
>
>
> -- 
> To post to this group, send email to sage-support@googlegroups.com
> To unsubscribe from this group, send email to 
> sage-support+unsubscr...@googlegroups.com
> For more options, visit this group at 
> http://groups.google.com/group/sage-support
> URL: http://www.sagemath.org

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to