[Tutor] problem solving with lists

Dennis Lee Bieber wlfraed at ix.netcom.com
Mon Mar 7 13:28:49 EST 2022


On Mon, 07 Mar 2022 11:46:42 -0500, Dennis Lee Bieber
<wlfraed at ix.netcom.com> declaimed the following:


>	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.
>

	AND....

	Using set intersection appears to fail (runs out of candidates). 

[['abcd', 'aefg', 'ahij', 'aklm'],
 ['anop', 'behk', 'bfil', 'bgjm'],
 ['ceim', 'cfhn', 'cgko', 'cjlp'],
 ['dejn', 'dfkp', 'dghl'],
 []]

My combinations/set intersection ran out at only 15 quads. Perhaps your
description of the acceptance criteria is ambiguous.

Original>   with constraint that a pair of letters, p.e. ['a', 'b', ..] can
occur
Original> only once in all 20 sublists

	Set intersection means that, say "afmp" is in the accepted list, then
"fgim" would be rejected as "f" and "m" are common to both quad-letter
strings.

	Is the requirement that ADJACENT PAIRS (in sorted order) result in
rejection -- so both "afmp" and "fgim" are accepted, but "fmop" would be
rejected as "afmp" and "fmop" have "fm" as adjacent pairs? Or is it even
more constrained -- and the adjacent pairs must be at the same offset in
the strings?

	Changing my filter logic to use adjacent pairs, but anywhere in the
quad, results in

[['abcd', 'acef', 'adeg', 'aehi'],
 ['afgh', 'agij', 'ahjk', 'aikl'],
 ['ajlm', 'akmn', 'alno', 'amop'],
 ['bdfh', 'beil', 'bfim', 'bgjm'],
 ['bhkn', 'binp', 'cfjn', 'cgko']]

FYI:		Running without a limit of 20 accepted resulted in a total of
only 23 quads passing.

[['abcd', 'acef', 'adeg', 'aehi'],
 ['afgh', 'agij', 'ahjk', 'aikl'],
 ['ajlm', 'akmn', 'alno', 'amop'],
 ['bdfh', 'beil', 'bfim', 'bgjm'],
 ['bhkn', 'binp', 'cfjn', 'cgko'],
 ['chlo', 'dglp', 'dhmp']]

	If I assume the pairs must be in the same offset position, I get 35
quads

[['abcd', 'acde', 'adef', 'aefg'],
 ['afgh', 'aghi', 'ahij', 'aijk'],
 ['ajkl', 'aklm', 'almn', 'amno'],
 ['anop', 'bceg', 'bdfh', 'begi'],
 ['bfhj', 'bgik', 'bhjl', 'bikm'],
 ['bjln', 'bkmo', 'blnp', 'cdgj'],
 ['cehk', 'cfil', 'cgjm', 'chkn'],
 ['cilo', 'cjmp', 'deim', 'dfjn'],
 ['dgko', 'dhlp', 'efkp']]

NOTE:	All solutions are using itertools.combinations and
itertools.filterfalse, but differ on the filter predicate function.

{Now, do I want to attempt to code a string combinations generator/iterator
in REXX -- I'll need to study if it supports "static" data (previous value
retained between invocations) in procedures. Otherwise there may be some
ugly global data exposed; filterfalse generator/iterator isn't really
required as the filter predicate can be manually called}



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



More information about the Tutor mailing list