Jay Miller3

Q: pairing groups which will not repeat

Pairings groups which will not repeat

 

I teach and would like to pare students (21 students in total) into pairs of 2 students in each pairing. Each week the pairings will change so students are matched with another student. I do not want to repeat the same pairing for as long as I can delay that.

 

Does anyone know a "simple" or straightforward way to use Pages to keep track of those 2-person pairings and visibly show (to me) what the next pairings will be?

 

Thank you.

MacBook Pro (15-inch Mid 2010), Mac OS X (10.7.5), 2.53 GHz Intel Core i5, 4 GB 1067 MHz DDR3

Posted on Aug 21, 2016 6:06 AM

Close

Q: pairing groups which will not repeat

  • All replies
  • Helpful answers

  • by PeterBreis0807,

    PeterBreis0807 PeterBreis0807 Aug 21, 2016 7:23 AM in response to Jay Miller3
    Level 8 (35,830 points)
    Mac OS X
    Aug 21, 2016 7:23 AM in response to Jay Miller3

    Interesting exercise.

     

    What do you do with the odd one out?

     

    Peter

  • by VikingOSX,

    VikingOSX VikingOSX Aug 21, 2016 9:32 AM in response to Jay Miller3
    Level 7 (21,562 points)
    Mac OS X
    Aug 21, 2016 9:32 AM in response to Jay Miller3

    This is a combinations (nCr) problem with 210 unique pairing outcomes. The following Python script will generate those unique name pairs and write them out to a text file.

    #!/usr/bin/python

    # coding: utf-8


    # nCr combinations solution, read n choose r. Generate a unique list of combinations.

    # In this example, we take 21 students as n, and r = 2 is the pair combinations.

    # Usage: student_pairs.py names.txt > ~/Desktop/pairings.txt

    # names.txt is the student names, one per line.

    # output format: student name 1 : Student name 2

     

    import fileinput

    import itertools

    import sys

     

    student_list = []

    # read in student list and append their names in a list without newlines

    for line in fileinput.input(sys.argv[1:]):

        student_list.append(line.strip())

    # apply the nCr combinations formula to the student list as 21C2.

    for namepair in itertools.combinations(student_list, 2):

        print('{} : {}'.format(namepair[0], namepair[1]))

    sys.exit()

     

    Steps:

    1. Copy/paste the above script into TextEdit that already has Format menu : Make Plain Text set. Save as
      student_pairs.py (override TextEdit's insistence on .txt extension) to your Desktop.
    2. Open the Terminal application (Launchpad : Other : Terminal) Type only the blue text content below.

      # change directory to the Desktop

      $ cd ~/Desktop

      # make Python program executable

      $ chmod +x student_pairs.py

      # run the program with the student name list as input and produce the output file

      $ student_pairs.py names.txt > pairings.txt

     

    At this point, you have your generated list of name pairs, and you can open and format this in Pages. Quit the Terminal.

  • by PeterBreis0807,

    PeterBreis0807 PeterBreis0807 Aug 21, 2016 10:01 AM in response to VikingOSX
    Level 8 (35,830 points)
    Mac OS X
    Aug 21, 2016 10:01 AM in response to VikingOSX

    Viking

     

    I am trying to read your script.

     

    Since this is a SUM of a series 0 to 21, zero being NoPartner, I determined there were 231 pairs and each week there would be 11 pairs (one being a student with no pair) that is 21 weeks to go through all the pairs.

     

    As no student can be in 2 pairs simultaneously in the one week, I can not see how your script avoids this. It appears to generate a list of all possible pairs.

     

    Have I missed something?

     

    Peter

  • by VikingOSX,

    VikingOSX VikingOSX Aug 21, 2016 12:24 PM in response to PeterBreis0807
    Level 7 (21,562 points)
    Mac OS X
    Aug 21, 2016 12:24 PM in response to PeterBreis0807

    Peter,

     

    This Python script does strictly produce a mathematical combination of paired students. That is 210 (unique) pairs in the output. For 21 students each gets 21 - 1 (20 pairings). No one appears to be unpaired.

     

    Properly sorted in the Terminal

    $ combo.py names.txt | sort -t' ' -nk2 -nk5 > ~/Desktop/pairs.txt

     

    The above sorts individual student pairings numerically for better visual organization. If each student gets 20 unique pairings with another student, that would suggest that no pairing repetition should occur until week 21. The assumption is that pairings occur only once per week. The organization of those pairings can be taken from the generated pairing list, or by another organizational method.

  • by PeterBreis0807,

    PeterBreis0807 PeterBreis0807 Aug 21, 2016 1:28 PM in response to VikingOSX
    Level 8 (35,830 points)
    Mac OS X
    Aug 21, 2016 1:28 PM in response to VikingOSX

    I looked at this way:

     

    1. With 21 students every week one student faces an empty chair, NonPartner (0) ie 21 + 1, making actually 11 pairs/week

     

    2. Total unique pairs is 231 or 11 matches per week for 21 weeks.

     

    3. The complete list of pairs needs to be secondary sorted into 11 sets of pairs where no student is in two pairs each week.

     

    The third point was where I got bogged down. I could work out an algorithm, basically a sliding match up to week 11, then it became a progressive match upwards, always to a higher number with a check to see if there had been a previous match. That is where it got messy.

     

    Peter

     

    PS I can't be certain but my gut instinct says this is similar to a Sudoku solution where there is only one solution for the combinations of pairs over the 21 sets, but haven't got my head around how to write the sort other than a tedious working down, eliminating matches within sets one by one. I can eliminate the first 12 sets because they are progressions, its the last 9 that becomes a test by each case.

  • by PeterBreis0807,

    PeterBreis0807 PeterBreis0807 Aug 21, 2016 1:43 PM in response to VikingOSX
    Level 8 (35,830 points)
    Mac OS X
    Aug 21, 2016 1:43 PM in response to VikingOSX

    My initial idea of doing the sets by simple division and progression, looks like it may not resolve into complete sets over the entire 21 weeks.

     

    The tough nut is meeting both the unique pairing AND every single student is paired in only one pair per week.

     

    In practice, unless there was some reason to make every student partner with every other student without exception (not accounting for absences) I'd just run the exercise for the 12 easily sorted weeks and consider it a good mix.

     

    Peter

  • by PeterBreis0807,

    PeterBreis0807 PeterBreis0807 Aug 21, 2016 2:50 PM in response to Jay Miller3
    Level 8 (35,830 points)
    Mac OS X
    Aug 21, 2016 2:50 PM in response to Jay Miller3

    Any way you look at it this is not a problem to be solved by Pages.

     

    Peter

  • by VikingOSX,

    VikingOSX VikingOSX Aug 22, 2016 8:39 AM in response to PeterBreis0807
    Level 7 (21,562 points)
    Mac OS X
    Aug 22, 2016 8:39 AM in response to PeterBreis0807

    Agreed. Waiting for an OP response too. Been silent.

  • by SGIII,

    SGIII SGIII Aug 22, 2016 2:11 PM in response to Jay Miller3
    Level 6 (10,796 points)
    Mac OS X
    Aug 22, 2016 2:11 PM in response to Jay Miller3

    This seems to be a variation of the "round robin tournament problem." See table and formula-based suggested solution in cross-posting in Numbers for Mac Community.  Works in a Pages table too, though I think easier to set up in Numbers and copy into Pages if needed.

     

    SG

  • by VikingOSX,

    VikingOSX VikingOSX Aug 22, 2016 3:16 PM in response to SGIII
    Level 7 (21,562 points)
    Mac OS X
    Aug 22, 2016 3:16 PM in response to SGIII

    It is good that you posted this extensible, table/formula solution.

  • by Jay Miller3,

    Jay Miller3 Jay Miller3 Aug 24, 2016 9:22 AM in response to PeterBreis0807
    Level 1 (18 points)
    Notebooks
    Aug 24, 2016 9:22 AM in response to PeterBreis0807

    I merely pair with another 2 or have him/her be an "observer" with me.