Cartesian product of two or more lists: Difference between revisions

m
→‎version 1: changes some whitespace and comments.
m (→‎version 1: changed DO-END comments to match the DO statements.)
m (→‎version 1: changes some whitespace and comments.)
Line 2,498:
/* [↓] process each of the @.n values*/
do n=1 while @.n \= '' /*keep processing while there's a value*/
z= translate( space( @.n, 0), , ',') /*translate the commas to blanks. */
do #=1 until z=='' /*process each elements in first list. */
parse var z '{' x.# '}' z /*parse the list (contains elements). */
Line 2,507:
do j=i+1 for #-1 /* " " subsequent lists. */
do b=1 for words(x.j) /* " " elements of subsequent list*/
$=$',('word(x.i, a)","word(x.j, b)')' /*append partial cartesianCartesian product ──►$*/
end /*b*/
end /*j*/
end /*a*/
end /*i*/
say 'Cartesian product of ' space(@.n) " is ───► {"substr($, 2)'}'
end /*n */ /*stick a fork in it, we're all done. */</lang>
{{out|output|text=&nbsp; when using the default lists:}}
<pre>