close

Privacy guaranteed - Your email is not shared with anyone.

A program to really crunch numbers

Discussion in 'Tech Talk' started by ThinkOfTheChildren, May 17, 2006.

  1. ThinkOfTheChildren

    ThinkOfTheChildren C.E. Moderator

    Messages:
    813
    Likes Received:
    0
    Joined:
    May 2, 2000
    Location:
    USA
    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
     
  2. grantglock

    grantglock /dev/null

    Messages:
    219
    Likes Received:
    0
    Joined:
    Feb 20, 2004
    Location:
    Iowa

  3. prism

    prism more ammo

    Messages:
    1,477
    Likes Received:
    52
    Joined:
    Sep 26, 2002
    Location:
    Indiana
  4. hwyhobo

    hwyhobo

    Messages:
    1,426
    Likes Received:
    0
    Joined:
    Jun 3, 2003
    Location:
    Silicon Valley
    I would think any programming language that has conditionals and loops should work.
     
  5. David_G17

    David_G17 /\/\/\/\/\/\/\/

    Messages:
    2,046
    Likes Received:
    0
    Joined:
    Oct 7, 2002
    ~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.
     
  6. ThinkOfTheChildren

    ThinkOfTheChildren C.E. Moderator

    Messages:
    813
    Likes Received:
    0
    Joined:
    May 2, 2000
    Location:
    USA
    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 :)
     
  7. David_G17

    David_G17 /\/\/\/\/\/\/\/

    Messages:
    2,046
    Likes Received:
    0
    Joined:
    Oct 7, 2002
    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.
     
  8. neeko

    neeko

    Messages:
    499
    Likes Received:
    0
    Joined:
    Dec 22, 2002
    Location:
    Florida
    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
     
  9. ThinkOfTheChildren

    ThinkOfTheChildren C.E. Moderator

    Messages:
    813
    Likes Received:
    0
    Joined:
    May 2, 2000
    Location:
    USA
    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 :)
     
  10. David_G17

    David_G17 /\/\/\/\/\/\/\/

    Messages:
    2,046
    Likes Received:
    0
    Joined:
    Oct 7, 2002
    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.