Help Sorting users into groups of 5 and 6

4 views
Skip to first unread message

KB

unread,
Apr 12, 2012, 4:34:29 PM4/12/12
to model-glue
I have a list of users which is of a variable length. I need to sort
them into teams of 5 and 6, leaving nobody unassigned (when
possible).
I should minimize the total number of teams, creating as the most
number of 6 person teams and least number of 5 person teams possible.

Couple Examples:
1. If my list is 89 users long, create 14x6 and 1x5 (15 teams total)
2. If my list is 114 users long, create 19x6 and 0x5 (19 teams total)
3. If my list is 31 users long, create 1x6 and 5x5 (6 teams total)


You get the idea. How would you solve this programatically? In the
end, I need to update a database table assigning each user to a team.


I'm working out a solution, but I know there has to be a better way
and figured I'd tap into the collective brain power of this group for
help.


Thanks!


KB

Marc Bakker

unread,
Apr 13, 2012, 5:30:45 PM4/13/12
to model...@googlegroups.com

On the top of my head: (N mod 6) mod 5 =0 (where N is the number of users) creates the maximum nr of groups with 6 users and minimum nr of groups with  5 users.

Marc

_______________________
Verzonden van mobiel

Op 12 apr. 2012 22:34 schreef "KB" <kb1...@yahoo.com> het volgende:
--
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to model...@googlegroups.com
To unsubscribe from this group, send email to
model-glue+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Marc Bakker

unread,
Apr 14, 2012, 9:35:54 AM4/14/12
to model...@googlegroups.com

On the top of my head: (N mod 6) mod 5 =0 (where N is the number of users) creates the maximum nr of groups of 6 users and minimum of 5 users

_______________________
Verzonden van mobiel

Op 12 apr. 2012 22:34 schreef "KB" <kb1...@yahoo.com> het volgende:
I have a list of users which is of a variable length. I need to sort

Jochem van Dieten

unread,
Apr 15, 2012, 4:35:19 AM4/15/12
to model...@googlegroups.com
On Thu, Apr 12, 2012 at 10:34 PM, KB wrote:
> I have a list of users which is of a variable length. I need to sort
> them into teams of 5 and 6, leaving nobody unassigned (when
> possible).

What if that is not possible?

> I should minimize the total number of teams, creating as the most
> number of 6 person teams and least number of 5 person teams possible.

Total teams: #ceiling(players/6)#
Teams with 5 players: #(6 - players mod 6) mod 6#

Jochem

--
Jochem van Dieten
http://jochem.vandieten.net/

Reply all
Reply to author
Forward
0 new messages