Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mathematics knundrum
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00780672
Message ID:
00781097
Views:
28
Bruce, Rick

I got some spare time to analyze the program and now could answer your questions. (I still did not get response from authors, so no comments from them available at this time).

As far as I see, the program puts numbers in sequential order and sums them up until the target number is met. Then it starts another sum. So it does not calculate sums for all possible combinations. I cannot see anything wrong here.

Bruce, you mentioned that 20 is not correct count for the considered example (first 10 natural numbers and 40 as target number). Here are all 20 of them:

1+2+3+4+5+6+9+10=40
1+2+3+4+5+7+8+10=40
1+2+3+4+6+7+8+9=40
1+2+3+7+8+9+10=40
1+2+4+6+8+9+10=40
1+2+5+6+7+9+10=40
1+3+4+5+8+9+10=40
1+3+4+6+7+9+10=40
1+3+5+6+7+8+10=40
1+4+5+6+7+8+9=40
2+3+4+5+7+9+10=40
2+3+4+6+7+8+10=40
2+3+5+6+7+8+9=40
1+5+7+8+9+10=40
2+4+7+8+9+10=40
2+5+6+8+9+10=40
3+4+6+8+9+10=40
3+5+6+7+9+10=40
4+5+6+7+8+10=40
6+7+8+9+10=40

What do you see missing here?



>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?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform