Group Combination Generator - Help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lordvance
Forum Newbie
Posts: 3
Joined: Tue Oct 05, 2004 10:45 am
Contact:

Group Combination Generator - Help needed

Post by lordvance »

Hello everyone, I am new here, so I figured I would give a little tidbit about myself before I ask my question. My name is Kyle-Vance, I am 17 and currently attending my senior year of high school in Jersey. I have a class called "senior seminar" in which I can pretty much do whatever I want, as long as I accomplish something. I decided to do mine on 3d Modelling and Animation, but you have to "help the school" somehow. They through this assignment at me...

I have a "simple" assignment of creating a program.
Here is what it has to be able to do (step by step)
1: The user tells the program how many students (objects) it has
2: The user puts in a list of all of the students (objects) names
3: The user tells the program how many students (objects) it wants in every group
4: The program displays EVERY possible set of combinations without using the same two students (objects) in the same group, ever.
It would be great if the program save/load the list of students so that the teacher doesn’t have to retype the list over and over again.
for instance, 6 students, in groups of 2

AB CD EF
AC BE DF
AF DB CE

Notice that even though AC BF DE has not been used, A and C have already been in the same group.

A B C D E and F would all be student’s names (objects) and there would be 3 different possible sets of groups. Of course, this list would grow in size quite a bit depending on how many students/groups.

While I realize that this is a very complicated algorithm behind the program, I have a few months to get a finished product. I just need some resources for how to do this.

As for the programming language itself: I can use whatever I want, the only logical ones for me are HTML/PHP/JavaScript/Visual Basic as they are the only ones I can test/write from school (this has to be done 100% in school).
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it actually isn't all that complicated. The number of combinations is n^(n-1), where n is the number of students.

to write out the combinations, store all the student references into an array.

use two while/for loops, nested. The first is the combination marker. Each combination has a starting point and only moves down the list of students. So, AB AC AD AE AF, BC BD BE BF, CD CE CF...

see the pattern?
lordvance
Forum Newbie
Posts: 3
Joined: Tue Oct 05, 2004 10:45 am
Contact:

Post by lordvance »

Thanks very much for the reply :-D

I think I am seeing this wrong, 3 students = 3^2 = 9
however, the only results I see that work are

AB AC and BC, which is only 3.

am I wrong here, or did I explain what I was trying to do wrong


in any case, you gave me a really exelent idea.

I could have it generate the list of AD AE AF BC BD BE BF...yada yada, and then give each of those a groupid, and then form unique combinations from that....dunno how much sence I am making, hungry :-D

thanks alot for the reply, I look forward to hearing from you again
lordvance
Forum Newbie
Posts: 3
Joined: Tue Oct 05, 2004 10:45 am
Contact:

Post by lordvance »

I just realized exactly what you were saying with the AB AC AD AE AF, BC BD BE BF, CD CE CF, DE DF, EF....that would work perfectly

my concern is that the number of students is dynamic, so it could be AB AC...or it could be ABC ADE AFG
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yeah.. that's not a big step beyond the first path though.. just a bit more into recursion.. here's a hint, work backwards in how you pair students together. BC, BD, BE, BF .. with tacking on A to each.. kinda thing.. only more algorithmic.

basically.. create a complete list of a single pair of students. Now create a list of other students paired with those results, and so on.
Post Reply