Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5938207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:39:07+00:00 2026-05-22T15:39:07+00:00

array 1703 => float 15916.19738 5129 => float 11799.15419 33 => float 11173.49945 1914

  • 0
array
1703 => float 15916.19738
5129 => float 11799.15419
33 => float 11173.49945
1914 => float 8439.45987
2291 => float 6284.22271
5134 => float 5963.14065
5509 => float 5169.85755
4355 => float 5153.80867
2078 => float 3932.79341
31 => float 3924.09928
5433 => float 2718.7711
3172 => float 2146.1932
1896 => float 2141.36021
759 => float 1453.5501
2045 => float 1320.74681
5873 => float 1222.7448
2044 => float 1194.4903
6479 => float 1074.1714
5299 => float 950.872
3315 => float 878.06602
6193 => float 847.3372
1874 => float 813.816
1482 => float 330.6422
6395 => float 312.1545
6265 => float 165.9224
6311 => float 122.8785
6288 => float 26.5426

I would like to distribute this array into two arrays both ending up with a grand total (from the float values) to be about the same. I tried K-Clustering but that distributes higher values onto one array and lower values onto the other array. I’m pretty much trying to create a baseball team with even player skills.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:39:08+00:00Added an answer on May 22, 2026 at 3:39 pm

    Step 1: Split the players into two teams. It doesn’t really matter how you do this, but you could do every other one.

    Step 2: Randomly switch two players only if it makes the teams more even.

    Step 3: Repeat step 2 until it converges to equality.

      $diff = array_sum($teams[0]) - array_sum($teams[1]);
      for ($i = 0; $i < 1000 && $diff != 0; ++$i)
      {
        $r1 = rand(0, 8); // assumes nine players on each team
        $r2 = rand(0, 8);
    
        $new_diff = $diff - ($teams[0][$r1] - $teams[1][$r2]) * 2;
    
        if (abs($new_diff) < abs($diff))
        {
          // if the switch makes the teams more equal, then swap
          $tmp = $teams[0][$r1];
          $teams[0][$r1] = $teams[1][$r2];
          $teams[1][$r2] = $tmp;
    
          var_dump(abs($new_diff));
    
          $diff = $new_diff;
        }
      }
    

    You’ll have to adapt that code to your own structures, but it should be simple.

    Here’s a sample output:

    int(20)
    int(4)
    int(0)
    

    I was using integers from 0 to 100 to rate each player. Notice how it gradually converges to equality, although an end result of 0 is not guaranteed.

    You can stop the process after a fixed interval or until it reaches some threshold.

    There are more scientific methods you could use, but this works well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Array 1 | Array 2 ================= 1 | 2 2 | 3 3 |
Array.Copy and Buffer.BlockCopy both do the same thing, but BlockCopy is aimed at fast
Array ( [4] => stdClass Object ( [vid] => 4 [name] => Movie [description]
Array ( [status] => success [stories] => Array ( [0] => Array ( [name]
Array ( [0] => Array ( [datas] => Array ( [name] => lorem [id]
Array starts like this: Array ( [SMART Board] => Array ( [0] => sb1
An array of ints in java is stored as a block of 32-bit values
Element[] array = {new Element(1), new Element(2), new Element(3)}; How do I convert the
The array has lots of data and I need to delete two elements. Below
array(2) { [0]=> object(stdClass)#144 (7) { [id]=> string(1) 2 [name]=> string(8) name1 [value]=> string(22)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.