Click to See Complete Forum and Search --> : Math Help Sorting 10 numbers
perito
Dec 16th, 2008, 06:48 AM
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.
Hack
Dec 16th, 2008, 07:05 AM
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. :)
Ebiru
Dec 17th, 2008, 07:45 PM
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.
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.