[Tutor] problem solving with lists

Dennis Lee Bieber wlfraed at ix.netcom.com
Mon Mar 21 15:14:53 EDT 2022


On Mon, 21 Mar 2022 18:34:40 +1300, dn <PythonList at DancesWithMice.info>
declaimed the following:

>Which all serves to make me think that I have yet to grasp the
>full-measure of the problem!
>

	Is your solution generalized enough to handle the classic SGP test?

		8 groups of		4 players over		10 weeks

According to the research, there IS a solution to this.

	I've spent the afternoon hacking my previous code to work in loops of
		weeks
			groups in week
using set intersection as the filter (within week, intersection between
groups must return empty sets -- no duplicate players) and then against
prior weeks (intersection must not be greater than 1; 2+ indicates a
repeated pair of players). The 4 4 6 case is an expected result.

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py

***     Usage: SGP.py number_of_groups group_size number_of_weeks


C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 4 4 1
Week # 0:       abcd    efgh    ijkl    mnop

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 4 4 2
Week # 0:       abcd    efgh    ijkl    mnop
Week # 1:       aeim    bfjn    cgko    dhlp

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 4 4 3
Week # 0:       abcd    efgh    ijkl    mnop
Week # 1:       aeim    bfjn    cgko    dhlp
Week # 2:       afkp    belo    chin    dgjm

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 4 4 4
Week # 0:       abcd    efgh    ijkl    mnop
Week # 1:       aeim    bfjn    cgko    dhlp
Week # 2:       afkp    belo    chin    dgjm
Week # 3:       agln    bhkm    cejp    dfio

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 4 4 5
Week # 0:       abcd    efgh    ijkl    mnop
Week # 1:       aeim    bfjn    cgko    dhlp
Week # 2:       afkp    belo    chin    dgjm
Week # 3:       agln    bhkm    cejp    dfio
Week # 4:       ahjo    bgip    cflm    dekn

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 4 4 6

*****   NO SOLUTION FOUND       *****

	However, for the classic problem (remember, a solution IS known for 8 4
10), I get...

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 1
Week # 0:       abcd    efgh    ijkl    mnop    qrst    uvwx    AByz CDEF

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 2
Week # 0:       abcd    efgh    ijkl    mnop    qrst    uvwx    AByz CDEF
Week # 1:       aeim    bfjn    cgko    dhlp    Cquy    Drvz    AEsw BFtx

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 3
Week # 0:       abcd    efgh    ijkl    mnop    qrst    uvwx    AByz CDEF
Week # 1:       aeim    bfjn    cgko    dhlp    Cquy    Drvz    AEsw BFtx
Week # 2:       afkp    belo    chin    dgjm    AFqv    BEru    Dsxy Ctwz

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 4
Week # 0:       abcd    efgh    ijkl    mnop    qrst    uvwx    AByz CDEF
Week # 1:       aeim    bfjn    cgko    dhlp    Cquy    Drvz    AEsw BFtx
Week # 2:       afkp    belo    chin    dgjm    AFqv    BEru    Dsxy Ctwz
Week # 3:       agln    bhkm    cejp    dfio    BDqw    ACrx    Fsuz Etvy

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 5
Week # 0:       abcd    efgh    ijkl    mnop    qrst    uvwx    AByz CDEF
Week # 1:       aeim    bfjn    cgko    dhlp    Cquy    Drvz    AEsw BFtx
Week # 2:       afkp    belo    chin    dgjm    AFqv    BEru    Dsxy Ctwz
Week # 3:       agln    bhkm    cejp    dfio    BDqw    ACrx    Fsuz Etvy
Week # 4:       ahjo    bgip    cflm    dekn    Eqxz    Frwy    BCsv ADtu

C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 6

*****   NO SOLUTION FOUND       *****


C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 7

*****   NO SOLUTION FOUND       *****


C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 8

*****   NO SOLUTION FOUND       *****


C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4 9

*****   NO SOLUTION FOUND       *****


C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>main.py 8 4
10

*****   NO SOLUTION FOUND       *****


C:\Users\Wulfraed\Documents\_Hg-Repositories\Python Progs\SGP>

...	so it is apparent that my current version is missing some aspect. I'm
not thinking of adding telemetry/debug to find out where the higher cases
are triggering rejects. 

	"No solution found" is what I dump when itertools.combinations() runs
out of values (StopIteration exception). I restart .combination() for each
week in order to reclaim combinations that were skipped in the previous
week.

	While "1 week" is no problem (I can run 15 groups of 4 for 1 week) my
program fails to even get a second week of 5 groups of 4

	I have no back-tracking in place, beyond the restart of the generator
on each week. I suspect the next attempt -- should I get ambitious -- is to
put a generator on each group in each week (and save them as some
structure), to allow for back-tracking.


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



More information about the Tutor mailing list