Amb: Difference between revisions

Content added Content deleted
m (→‎version 1: split a one-line DO loop into two statements.)
Line 2,957: Line 2,957:
An assumption was made that equivalent lowercase and uppercase (Latin) letters are considered a match.
An assumption was made that equivalent lowercase and uppercase (Latin) letters are considered a match.
<lang rexx>/*REXX program demonstrates the Amd operator, choosing a word from each set. */
<lang rexx>/*REXX program demonstrates the Amd operator, choosing a word from each set. */
@.=; @.1 = "the that a"
@.=; @.1 = "the that a"
@.2 = "frog elephant thing"
@.2 = "frog elephant thing"
@.3 = "walked treaded grows"
@.3 = "walked treaded grows"
@.4 = "slowly quickly"
@.4 = "slowly quickly"
call Amb 1 /*find all word combinations that works*/
call Amb 1 /*find all word combinations that works*/
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
Amb: procedure expose @.; parse arg # x; arg . u /*2nd parse uppercases U*/
Amb: procedure expose @.; parse arg # x; arg . u /*ARG uppercases U values. */
do j=1 until @.j==''; end /*locate a null string. */
do j=1 until @.j=='' /*locate a null string. */
t=j-1 /*define number of sets.*/
end /*j*/
if #>t then do; w=word(u,1) /*W: is a uppercased U*/
t= j-1 /*define number of sets. */
do n=2 to words(u); ?=word(u, n)
if #>t then do; y=word(u, 1) /*Y: is a uppercased U. */
if left(?, 1) \== right(w, 1) then return; w=?
do n=2 to words(u); ?=word(u, n)
end /*n*/
if left(?, 1) \== right(y, 1) then return; y=?
say space(x)
end /*n*/
say space(x) /*¬show superfluous blanks.*/
end
end


do k=1 for words(@.#) /*process words in sets.*/
do k=1 for words(@.#); call Amb #+1 x word(@.#, k)
call Amb #+1 x word(@.#, k) /*generate combinations,*/
end /*k*/ /* [↑] generate all combs */
end /*k*/ /* [↑] (recursively).*/
return /* recursively. */</lang>
return</lang>
{{out|output|text=&nbsp; when using the default internal input:}}
{{out|output|text=&nbsp; when using the default internal input:}}
<pre>
<pre>