[Tutor] problem solving with lists

Dennis Lee Bieber wlfraed at ix.netcom.com
Sun Mar 20 12:05:16 EDT 2022


On Sun, 20 Mar 2022 15:55:27 +0100, <marcus.luetolf at bluewin.ch> declaimed
the following:

>>all_letters = ‘abcdefghijklmnop’ 
>>number_of_lists = 5
>>number_of_sublists per list = 4
>>number_per_sublist = 4
>to
>>all_letters = ‘abcdefghi’ 
>>number_of_lists = 4
>>number_of_sublists per list = 3
>>number_per_sublist = 3
>to
>>all_letters = 'abcdef'.
>

	The discussion would be much easier if you gave real names to all
those... (since you later confirm this is the SGP)

	number of weeks
	number of groupings
	players per grouping

This avoids all confusion over lists, sublists, etc... "week 1", "group 3",
"player 2".

>What means "OP", "32 nicely formated LoC", "PEP-8 spacings" ???
>

	"Original Poster" -- you, the person who started this thread
	"Lines of Code". Mine isn't as compact, taking 54 lines including blank
and comment-only lines
	"Python Enhancement Proposal" (as I recall). PEP-8 being concerned with
how Python code should be formatted -- primarily for inclusion in the
Python library, though others have standardized on its recommendations.

>seems rather straightforward.  But for now I cannot see yet how to use it to remove all non-uniques sublists/teams.

	You don't "remove" them! "Remove" implies you already placed a grouping
into the solution and now are checking for if they meet the constraints.
Instead you check the constraints for a candidate grouping BEFORE ADDING it
to the solution.

>SPG exactly describes my goal.

	The SGP is not a week-end programming exercise. It is the subject of
multiple university research papers in developing/optimizing
constraint-based solver algorithms.

	A one-time pass over the output of .combinations() will not be
sufficient (especially as the criteria per week that no player appears more
than once means going from "abcd" [the first foursome .combinations() spits
out] has to skip all other groups that begin with "a", "b", "c" or "d" --
and you can't get them back later. At a minimum you need to restart the
.combinations() on each week. You'll really need to implement some way of
backtracking ("we ran out of groupings without being able to place one in
'this' position, back up and change the previously placed grouping and
start over on this position") -- it is possible you might have to back all
the way up to the first grouping and try a different value for it.


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



More information about the Tutor mailing list