3

we are doing a hackathon at work and I need to assign each staff into teams.

I am trying to match each team so they have the same amount of experience (within 2 years hopefully).

I was hoping to write a quick javascript program to do this, as there will be just under 50 staff taking part (split into 10 teams). They will fill in a quick online form which states their experience on the day and I hoped a quick JS function would sort it.

I was going to sort each person based on experience and simply assign them to a team e.g.

  • dave - 2 years
  • steve - 4 years
  • adil - 4 years
  • predeesh - 5 years
  • adam - 5 years
  • john - 7 years

so if I had two teams I would place dave in the first team, steve in the second, adil in the first team, predeesh in the second and so on. however this does not quite work out as team one has 11 years and team two has 16 years.

I wanted to try and get the gap as close as possible. Is there any maths formula I could use for this that would solve the issue.

I could do it by hand, but everyone is coming on the day and its a bit of a pain to wait and sort it out by hand.

Thanks

  • so you want to get two teams or a variable number of teams? – Nina Scholz Apr 20 '16 at 11:27
  • So if you have `n` number of people, you want to divide them in `m` teams with n > m, and total weight of each team (sum of experience) should be simillar? (minimum variance) – gurvinder372 Apr 20 '16 at 11:29
  • @NinaScholz there will be 10 teams, with hopefully 50 people (five per team). – david johnson Apr 20 '16 at 11:42
  • @gurvinder372 yes thats spot on. – david johnson Apr 20 '16 at 11:42
  • 1
    @davidjohnson have a look at http://www.americanscientist.org/issues/pub/the-easiest-hard-problem and http://stackoverflow.com/questions/6597180/divide-an-array-into-two-sets-with-minimal-difference ... This is basically toughest problem to solve. – gurvinder372 Apr 20 '16 at 11:46
  • @gurvinder372 thank you very much for sending them links. Ill check them out. I knew it was a tough one as its the first time ive not been able to find a solution and needed to ask a question. thanks again. – david johnson Apr 20 '16 at 11:58
  • Do teams have to have 5 people? you can have equal experience teams with different number of people... – pseudoDust Apr 20 '16 at 12:01
  • @pseudoDust they do unfortunately, we only have desks that fit 5 people (well six but would be cramped with all laptops etc). its more of a team building exercise as well, so a team of 5 seems the most appropriate. – david johnson Apr 20 '16 at 12:05
  • That actually makes your problem simpler, if you had to manage different sized teams the search space gets bigger, this is an NP-hard problem, but given your input size you might be able to brute force a solution by building team by team and back tracking when ever you get stuck(unable to build a team close enough to the average xp per team) – pseudoDust Apr 20 '16 at 12:12
  • 1
    What a great link from @gurvinder372. Thank you for posting. – duffymo Apr 20 '16 at 12:42

1 Answers1

0

Maybe this can help you to start your solution. You need to find out the mean experience of all your staff and then multiply that for the number of people per team and get the mean experience per team.

In your example if you want 2 teams of 3 people, you'll have 13'5 years of experience as mean experience per team. Then you need to team up 3 people with that total number of years of experience (or in this case the closest integer, 13 or 14).

Knowing the required experience per team, you "just" need to find all the possible combinations of teams with 13 or 14 years of experience.

To do it in your example, I started taking the person with the most experience and teaming him up with the one with the least experience, but depending on how you store the staff in your program it may vary.

I know it's not a complete solution, but I hope it helped and that I could explain myself.