0

The Kirkman's Schoolgirl Problem aims to form groups of three girls for some 'n' number of days such that no pair of girls are ever together more than once in the same group. For this I was working with 9 girls that need to be divided in groups of three for 4 days.

I am very new to Python. I would like to avoid fancy modules for now, so I can get my basics right.

Here is my code:

prob = ['ariana', 'barbara', 'cindy', 'darlyn', 'emily', 'felicia', 'gwanyth', 'hilton', 'india', 'julie']
same_grps = []
days_arrangement = []
while len(days_arrangement)<=4:
    today = []
    same_day = []
    for i in range(3):
        while True: 
            temp = []
            temp_same_day = []
            for j in range(3):
                for girl in prob:
                    if girl not in temp_same_day:
                        temp.append(girl)
                        temp_same_day.append(girl)
            if temp in same_grps:
                continue
            if temp not in same_grps:
                grp = temp[::]
                same_grps.append(grp)
                today.append(grp)
                break
    days_arrangement.append(today)
print(days_arrangement)

When I run it the kernel doesn't respond, as if stuck in some infinite loop and gives no output.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 2
    Didn’t you try debugging, e.g. by adding some simple print statements to indicate progress within each loop? – DisappointedByUnaccountableMod Apr 17 '21 at 08:19
  • You seem to get stuck in the inner while loop, as soon `temp in same_grps` turns True for some reason. `same_grps` is not modified in this part of loop, and any variables (`temp` and `temp_same_day`) that are modified, are computed anew. – Vytas Apr 17 '21 at 08:39
  • You probably need to make sure that a) `temp` is sorted before being put in `same_grps` and before the `if temp in same_grps` line. There’s no point in the `if temp not in same_grps` line. – DisappointedByUnaccountableMod Apr 17 '21 at 18:25
  • 9 or 10 girls? Your list have 10 of them? – sinisake Apr 18 '21 at 11:38
  • @Sandrider345, there's a solution here, https://stackoverflow.com/questions/56129886/how-to-use-z3-solver-to-solve-kirkman-s-schoolgirl-problem. – Mark K Jan 03 '22 at 14:03

0 Answers0