Jump to content

Amb: Difference between revisions

82 bytes added ,  5 years ago
m
→‎version 1: split a one-line DO loop into two statements.
m (→‎version 1: split a one-line DO loop into two statements.)
Line 2,957:
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. */
@.=; @.1 = "the that a"
@.2 = "frog elephant thing"
@.3 = "walked treaded grows"
@.4 = "slowly quickly"
call Amb 1 /*find all word combinations that works*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Amb: procedure expose @.; parse arg # x; arg . u /*2nd parseARG uppercases U values. */
do j=1 until @.j==''; end /*locate a null string. */
t=j-1 end /*define number of sets.j*/
if #>t= j-1 then do; w=word(u,1) /*W:define number isof asets. uppercased U*/
if #>t then do; y=word(u, 1) do n=2 to words(u); /*Y: is a ?=word(u,uppercased n)U. */
if left(?, 1) \== right(w, 1) do thenn=2 return to words(u); w=?=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
 
do k=1 for words(@.#); call Amb #+1 x word(@.#, /*process words in sets.*/k)
end /*k*/ call Amb #+1 x word(@.#, k) /* [↑] generate combinations,all combs */
return end /*k*/ /* [↑] ( recursively). */</lang>
return</lang>
{{out|output|text=&nbsp; when using the default internal input:}}
<pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.