|
-
Dec 16th, 2008, 07:48 AM
#1
Thread Starter
Addicted Member
Math Help Sorting 10 numbers
I'm basically looking for a good algorithm or method to do the following:
I have 10 numbers, you can use List<Integer> or int[] or what ever u want.
I want to sort the 10 numbers so the sum of the first 5 is approximately (or exactly if possible) equal to the sum of the last 5. The sum of the first 5 must be as close as possible to the sum of the last 5.
How can I do that?
Thanks.
Im using Visual Studio 2008 Professional Edition
.Net Framework 3.5
-
Dec 16th, 2008, 08:05 AM
#2
Re: Math Help Sorting 10 numbers
VBForums enjoys seeing a good faith effort on your part before providing source code examples.
Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance.
Be sure to include the description of any errors (number as well as text) you are encountering as well.
Thank you.
-
Dec 17th, 2008, 08:45 PM
#3
Addicted Member
Re: Math Help Sorting 10 numbers
 Originally Posted by perito
I'm basically looking for a good algorithm or method to do the following:
I have 10 numbers, you can use List<Integer> or int[] or what ever u want.
I want to sort the 10 numbers so the sum of the first 5 is approximately (or exactly if possible) equal to the sum of the last 5. The sum of the first 5 must be as close as possible to the sum of the last 5.
How can I do that?
Thanks.
Code:
int totalA = 0;
int totalB = 0;
int[] nums = new Integer[10]
for(int x = 0; x < 5; x++)
{
totalA = totalA + nums[x];
totalB = totalB + nums[x*2];
}
if(totalA == totalB)
{
enter code
}
im not sure if thats what u wanted but there u go, just make sure u set the nums to the values
if u wanted so a bunch of rnd numbers r selected and short please reply saying so
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|