Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mathematics knundrum
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00780672
Message ID:
00780760
Vues:
13
Bruce thanks for explanation. My mathematical knowledge is very limited, so you would be hard pressed to insult it. The theory is definitely beyond my mathematical abilities. I've been working on a rather ugly brute force program to solve it. I'll take a look at Yuri's routines. Thanks!

>>I'm working on a reconciliation project and i'm stuck. I have a list of numbers lets say 100 numbers and I have a target amount that some permutation of these numbers adds up to. I don't know how many of them will add up to this number. I need the list of numbers that adds up to my target number. I tried writing this but my brain overworked itself. Anybody ever write something like this or have any ideas? Thanks in advance!!!
>>
>>Example
>>Say my number is 362.21 and my number list is:
>>201.10
>>25.18
>>150.11
>>778.88
>>151.21
>>11.31
>>10.00
>>...
>>The answer is 201.10 150.11 and 10.00
>
>I've done this type of thing before, Marvin. First, what you want are called "Combinations," not Permutations. Combinations are where the order doesn't matter, and this makes the sum checks a lot less in number, though also a little harder to code too. Second, using some math terms might help to see what your task is a little better. We term combinations using factorials: C(n,k) = n!/(n-k)!*k!, where n! = n*n-1*n-2...1. 4! = 4*3*2*1, for example. n is the number of numbers you need to check through, and k is a counter for each n-tuple you are checking.
>
>You may well already know this, of course, and I don't mean to offend your math knowledge if anything I'm explaining is redundant to you.
>
>So then logically, what you need to do is check all the sum combinations of each C(n,k) until you find a target match or END with no match. Say you put the base numbers in table with n records, and have a target sum, call it nTarget.
>
>Then the job is to check for a match with nTarget through every group of C(n,k) sums, where k = 1 to n. For n = 4 then, you check the C(4,1)s - each number by itself. Then all the C(4,2)s - the sums of all 2-number combinations. Then C(4,3)s - sums of all 3-number combinations. Then C(4,4)s - the sum of the one 4-number combination.
>
>This is just a theoretical solution, which I figured is a good starting point: to understand exactly what you need to do logically. Someone else (Yuri) just posted some code links, and they may well do what you need (I haven't looked at them yet) - but I just wanted to begin with an explanation of the underlying math & terminology, as it's always good to understand the underlying logic before attempting to code anything.
>
>Let me know if you still are having any trouble after looking at Yuri's code links, I should have some looping code somewhere that does this sort of thing already. It's a little bit tricky, since you have to make loop exclusions so you don't sum any numbers twice in any given combination sum.
Marvin Masson
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform