# [Tutor] problem solving with lists

Dennis Lee Bieber wlfraed at ix.netcom.com
Sun Mar 20 11:25:34 EDT 2022

```On Sun, 20 Mar 2022 16:35:44 +1300, dn <PythonList at DancesWithMice.info>
declaimed the following:

>So, first criticism is that line 1:
>
>0 [['a', 'b', 'c', 'd'], ['b', 'c', 'd', 'e'], ['c', 'd', 'e', 'f'],
>['d', 'e', 'f', 'g']]the
>
>should be more like:
>
>0 [['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'], ['i', 'j', 'k', 'l'],
>['m', 'n', 'o', 'p']]
>
>but when it comes to the next list, would
>
>['a', 'c', 'd', 'e']
>
>be unacceptable because although the 'b' has been dropped, the first
>three all served-together previously.
>
As I understand it, that is dead three times over: AC, AD, and CD ...
presuming the intent is the strict Social Golfer's Problem (no pairing
occurs more than once, but some pairings may never appear). The relaxed SGP
(all pairings occur at least once, some pairings may repeat) might accept
it -- though some sort of scoring mechanism would be needed (is one repeat
each of AC, AD, and CD better or worse than three repeats of just AC?) to
rank multiple solutions.

I could see a time-consuming inefficient procedure that recurses for
each week, and each layer has its own combinations() iterator. For each
layer (week) loop obtaining a grouping; verify that the grouping shares no
players with other groupings in that same week AND that is does not share
any pairs with previously accepted groupings (if it does, reject and draw
another grouping; if one runs out of groupings, back up and reject previous
layer). Properly done, this also needs to be able to backtrack within each
week -- and that may require having an iterator for each position in the
solution (and iterators that get reset when that position is rejected and
one has to move the previous position).

--
Wulfraed                 Dennis Lee Bieber         AF6VN
wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

```