[Tutor] problem solving with lists

Dennis Lee Bieber wlfraed at ix.netcom.com
Thu Mar 24 13:26:58 EDT 2022


On Thu, 24 Mar 2022 11:41:45 -0400, Dennis Lee Bieber
<wlfraed at ix.netcom.com> declaimed the following:

>
>	Keep your players as a string. Think of your "team" as a unit, made out
>of a string.
>
>	Strings are indexable -- the syntax looks just like what you'd use with
>a list of 1-char strings).
>

	Alternatively -- don't use LIST or STRING... Since for purposes of the
problem itself, there is no difference between

"abcd" and "dbac" (and similarly, there is no difference between
"abcd", "efgh", "ijkl", "mnop" and "ijkl", "abcd", "mnop", "efgh")

you should be thinking of using SET as a data structure.

	You state you are trying to come up with an algorithm, but your
description is always at the level of implementation at the low-level of
the language itself -- and you have already defined a one-use
implementation.

	An algorithm would be something like:

{	
	/w/ 	<= a week
	/nw/	<= number of weeks
	/g/		<= a group
	/ng/	<= number of groups
	/pg/	<= player in group
	/sg/	<= size of group
	/p/		<= a player
}
	for each /w/ in /nw/ weeks
		for each /g/ in /ng/ groups 
			for each /pg/ in  /sg/ players-in-group
				select /p/ from (pg * g) players
					such that /p/ is only selected once in the current week
					AND
					any pair of /p/ in /pg/ does not appear in any prior
week's groups


	At an implementation level -- .combinations() does most of the 
		for each /pg/ ...
			select /p/ ...
in that it will return /sg/ size groups of /p/, and within the group, there
are no duplicates. You are still responsible for testing that they are
unique across the groups in each week (that means rejecting many of the
groups that .combinations() will provide). If you use set logic, you don't
even have to index the members within each group.



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



More information about the Tutor mailing list