cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

A Programme works out all the possible answers?

Highlighted
Participant

A Programme works out all the possible answers?

Hi,

I need some ideas on how to do the following:

I have two variables a and b, the sum of a & b is 10. I would like Mathcad to work out all the possibilities that give me a+b=10, and a keep in mind I would like them to be integers.

Thank you

6 REPLIES 6
Highlighted

Re: A Programme works out all the possible answers?

If you just mean positive integers it's trivial:

ten.PNG

or have I misunderstood what you are looking for?

Alan

Highlighted

Re: A Programme works out all the possible answers?

What if I have a, b, c, d and e?

Highlighted

Re: A Programme works out all the possible answers?

Here's a brute force and ignorance method, again assuming positive integers only.

ten2.PNG

Alan

Highlighted

Re: A Programme works out all the possible answers?

Thank you, The brute force is working:)

Just for the fun of it, insteade of 9 use 99!

I am using Mathcad Prime and still runing around without result!

Highlighted

Re: A Programme works out all the possible answers?

HinndNaser wrote:

Thank you, The brute force is working:)

Just for the fun of it, insteade of 9 use 99!

I am using Mathcad Prime and still runing around without result!

It sure will be hard to find 99 numbers in the range of 1 to 9 which sum up to 10

Why not post the real problem you are working on? But whatever its is, Mathcad provides no clever algorithms to deal with integers, diophantic equations or number theory in general. So brute force seems to be a quick and dirty option, but with a lot of values to deal with and probably a wider range per variable, its not an option still anymore as it will take more time than you are willing and able to spend. So the problem might be solveable by an approach unique to that specific problem.

In case you are interested in a way to write a routine with an arbitrary number of variables on not a static number of nested for loops, take a look at the routine I posted here: http://communities.ptc.com/message/199660#199660

The routine sure could be modified to solve tasks as your with a variable number of arguments, arbitrary function s (not only summation of all arguments) and a target value (like th 10 in your example).

But it will very soon get too slow to be helpful.

You may also be interested in this thread: http://communities.ptc.com/message/194291#194291

Highlighted

Re: A Programme works out all the possible answers?

Are you placing bounds on a and b? Integers, fine. Positive? Or are negative values allowed? Count "0" as an integer?

Announcements