Factoring Logic

Hi,

How will you factor out data with different values to match to another value.
For example:

value A=100
value B=50,10,20,5,15,20,30

How will you construct a logic that the values on value B will have an equal value as value A.

100 = 50+20+10+20 or 100 = 50+30+20 and so on and so forth.

I am stuck with this for ages.

Thanks.



I think you could use the Backtracking algorithm:
http://en.wikipedia.org/wiki/Backtracking
http://www.cse.ohio-state.edu/~gurari/course/cis680/cis680Ch19.html

You should order the values of B in increasing order, such as:

value A=100
value B=50,10,20,5,15,20,30 => becomes
value B=5,10,15,20,20,30,50


This should make the Backtracking algorithm faster than a Brute-force search, because you can stop searching for suitable values of B as soon as the sum exceeds A.

Please read the Wikipedia article, and in particular pay attention to the Pseudocode section:
http://en.wikipedia.org/wiki/Backtracking#Pseudocode
Topic archived. No new replies allowed.