1 - 10 of 10 Posts

#### ThinkOfTheChildren

·
##### Registered
Joined
·
813 Posts
Discussion Starter · ·
What I'm really dreaming about here is a program that could take two lists of numbers (say each list is 50 variables) and then tell me all possible combinations in list 1 that could add up to any given item in list 2.

I know that's A LOT of calculations... but is there anything that could come close?

If that's not even remotely possible, could I find a program that could take 1 list of numbers (again, say around 50... maybe more) and then give me all possible combinations in it that would add up to a single sum?

Example, I'm looking for a sum of 27. I give the program the following list:
2, 21, 90, 1, 9, 4
And it says, "Use 21, 2, and 4, dummy!"

I know how to do this in Excel when only working with a small list (say 10 or so items) and a single sum, using the Solver tool... but the brute force nature of its methodology just becomes too lengthy when working with a list that is as large as mentioned above.

So does anyone know of anything out there that could do this?

Or any pointers in the right direction?

Thanks

·
Joined
·
219 Posts
matlab

·
Joined
·
1,487 Posts

#### hwyhobo

·
##### Registered
Joined
·
1,425 Posts
I would think any programming language that has conditionals and loops should work.

#### David_G17

·
##### /\/\/\/\/\/\/\/
Joined
·
2,046 Posts
Originally posted by ThinkOfTheChildren

So does anyone know of anything out there that could do this?
~raises hand~
me!

do you still need this?

how is your data set up? do you want to manually type in each value, or do you have a text file of numbers?

I may be bored this weekend, and need something to do.

is processing time important? the easiest way to code it is to use recursion - it would take a while to run through a dataset of tens of thousands of values, but 50 or so wouldn't matter.

#### ThinkOfTheChildren

·
##### Registered
Joined
·
813 Posts
Discussion Starter · ·
Yes, David, I need to do it almost every day

It's work related. The faster it can be accomplished the better, but given the fact that I do it manually right now, any "edge" is appreciated.

I work out of excel sheets, but could dump into a text file.

I could further (I think) simplify the solution to the problem by saying that a sum never really needs more than 4 or 5 items out of the list. And, of course, a sum can never include an item off of the list larger than the sum.

So that should take a large number of possible outcomes off the table right there.

Let me know what you think

#### David_G17

·
##### /\/\/\/\/\/\/\/
Joined
·
2,046 Posts
i meant to play with it this weekend, but got held up with work, computer problems, and other stuff.

I haven't forgotten

it's definitely doable.

#### neeko

·
##### Registered
Joined
·
499 Posts
is there a minimum or maximum combination from list1 to get a single value from list2?

testdata.txt
10 28
28 15
05 59
44 00

in this example above we have several solutions:
28 == 28
10+5 == 15
10+5+44 == 59

do you want the program interface like this?

enter list file name:
testdata.txt

enter amount of solutions:
3

solutions:
line 0, value 28
line 1, value 15
line 2, value 59

#### ThinkOfTheChildren

·
##### Registered
Joined
·
813 Posts
Discussion Starter · ·
Hi Guys,

Sorry for the delay in response: been away from the board for a little while.

I'd say that the minimum combination from list1 would be 2 items, while the max would be 5 items.

I guess my ideal interface would be one that asks me for a list, asks me for a sum to search (or a second list), then asks how many variables should be used in a sum (this would hopefully allow me to input a range... like 2-5).

Then, ideally, the program would first search for combinations of 2 in the list that make my sum. When those possibilities are exhausted it would search for combos of 3. And so on until the max-variables-used-in-sum is satisfied.

Outputting the results to a text would be great, as would some kind of easy break feature such that if the program is calculating too long, I can stop it without having to kill the task.

If any of this is too much, don't worry about it. I'm just always trying to find new ways of doing old things

#### David_G17

·
##### /\/\/\/\/\/\/\/
Joined
·
2,046 Posts
Originally posted by ThinkOfTheChildren
Hi Guys,

Sorry for the delay in response: been away from the board for a little while.

I'd say that the minimum combination from list1 would be 2 items, while the max would be 5 items.

I guess my ideal interface would be one that asks me for a list, asks me for a sum to search (or a second list), then asks how many variables should be used in a sum (this would hopefully allow me to input a range... like 2-5).

Then, ideally, the program would first search for combinations of 2 in the list that make my sum. When those possibilities are exhausted it would search for combos of 3. And so on until the max-variables-used-in-sum is satisfied.

Outputting the results to a text would be great, as would some kind of easy break feature such that if the program is calculating too long, I can stop it without having to kill the task.

If any of this is too much, don't worry about it. I'm just always trying to find new ways of doing old things
that's very doable, and I'll give it a try, but my fiance' came up for the holiday weekend - so if no one else gets something together, next tuesday I should be able to do it.

FWIW, any computer science student should be able to knock it out in about an hour or so.

1 - 10 of 10 Posts