[Tutor] problem solving with lists

Dennis Lee Bieber wlfraed at ix.netcom.com
Mon Mar 7 11:46:42 EST 2022


On Sun, 06 Mar 2022 13:05:26 -0500, Dennis Lee Bieber
<wlfraed at ix.netcom.com> declaimed the following:

>	Nested loops with differing increments (skips) may suffice.
>
>	Consider the first set of four substrings:
>abcd efgh ijkl mnop
>
>	Now, how to avoid any matching pairs? Well, you could take the "a", and
>one character from the other three substrings
>aeim afjn agko ahlp
>
>	But you can't do that with "b" -- as beim has "eim" in common. Instead
>of matching through "ijkl" you could wrap it -- "jkli".  (hint, use a
>modulo operator and just increment the position)
>bej. bfk. bgl. ghi.
>
>	Now you need to handle "mnop" to fill the "."; perhaps the same wrap?
>"nopm".
>bejn -- NO, conflicts with afjn.
>
>	So... an algorithm that needs to determine how much of a circular wrap
>each four-character substring needs after the first simple splitting, based
>upon which starting character is in play.

	I'll confess I spent too many hours yesterday trying to code a formula
that would produce viable cycles with no result. The best I managed was to
get three "rows" clear. Granted, just to wake up old skills, I was using
REXX for this and its 1-based indexing of strings kept complicating
matters.

	So... If full use of the Python standard library is a viable option... 

	Generate quad-letters (string of four letters, from the string of 16)
using itertools combinations. For each fetched quad-letter, perform a set
intersection operation against the elements of an "accepted" list. If the
fetched quad-letter passes, add it to the accepted list. Stop when
appropriate, format for output.

	I had a bit more detail before, but removed it as the above should be
sufficient to trigger reading in the library reference and start an
algorithm development. 

	If full use of the Python library is NOT PERMITTED... If not, you'll
need to specify what is permitted beyond lists, strings, and slices of
either -- and create your own functions for comparison, generation of
quad-letters (strings for length 4) from sixteen-letters (a single string
of a..p). DON'T think in terms of lists of four letters; pretty much
anything you'd do with that list can be done with a string. This route may
involve manually writing a combinations procedure -- should be a generator
function as you don't want to create all 1820 combinations and /then/
examine them; or coming up with some equation using row/col/char positions
to index into the 16-letter string.



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



More information about the Tutor mailing list