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:
00780819
Vues:
28
>Ok, I need to refresh my memory on this routines. Let us start with the pereb.prg (author Rustam Mukumov, most likely at rustam@sibron.ru).
>
>There is an array paNumbers(tnArray) containing the list of numbers. In the original code this array is created in the code and populated with integers; length of the array is the first program parameter.
>
>You need to pass your array to the program instead.
>
>The second parameter is the target total, and the third parameter indicates whether you need to list all of the solutions or you want to know only how many solutions are there.
>
>For example, you can run the original program like
>
>=pereb(10,40,.t.)
>
>to meet target total 40 for numbers from 1 to 10 in the list. You should see the list of 20 solutions.

No offense Yuri, as this is a somewhat tricky math problem, but 20 is not the right answer. You must chack ALL possible sums within the first 10 numbers: all the pair sums, all the triplet sums, all the quadruplet sums...all the way up to the sum of all 10 numbers at once.

The count of these sums is much larger: C(10,1) + C(10,2) + C(10,3) + ... + C(10,10),

Which is a total of 10 + 45 + 120 + 210 + 252 + 210 + 120 + 45 + 10 + 1 = 1,033 different possible sums that must all be checked, unless a "hit" is found and the loop can end sooner.

(If my math is correct, usually I let a program do the factorial & summing work :-)

Do these programs do this type of combination-checking?
The Anonymous Bureaucrat,
and frankly, quite content not to be
a member of either major US political party.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform