Results 1 to 3 of 3

Thread: Math Help Sorting 10 numbers

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  3. #3
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: Math Help Sorting 10 numbers

    Quote 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
  •  



Click Here to Expand Forum to Full Width