Cartesian product of two or more lists: Difference between revisions
Content added Content deleted
(add RPL) |
|||
Line 4,118: | Line 4,118: | ||
(4, 2) |
(4, 2) |
||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
≪ → a b |
|||
≪ { } |
|||
'''IF''' a SIZE b SIZE AND '''THEN''' |
|||
1 a SIZE '''FOR''' j |
|||
1 b SIZE '''FOR''' k |
|||
a j GET b k GET 2 →LIST 1 →LIST + |
|||
'''NEXT''' |
|||
'''NEXT''' |
|||
'''END''' |
|||
≫ ≫ '<span style="color:blue">CROIX</span>' STO |
|||
{1 2} {3 4} <span style="color:blue">CROIX</span> |
|||
{3 4} {1 2} <span style="color:blue">CROIX</span> |
|||
{1 2} {} <span style="color:blue">CROIX</span> |
|||
{} {1 2} <span style="color:blue">CROIX</span> |
|||
{{out}} |
|||
<pre> |
|||
4: {(1 3) (1 4) (2 3) (2 4)} |
|||
3: {(3 1) (3 2) (4 1) (4 2)} |
|||
2: {} |
|||
1: {} |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
"product" is a method of arrays. It takes one or more arrays as argument and results in the Cartesian product: |
"product" is a method of arrays. It takes one or more arrays as argument and results in the Cartesian product: |
||
Line 4,136: | Line 4,159: | ||
[] |
[] |
||
</pre> |
</pre> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
<syntaxhighlight lang="rust">fn cartesian_product(lists: &Vec<Vec<u32>>) -> Vec<Vec<u32>> { |
<syntaxhighlight lang="rust">fn cartesian_product(lists: &Vec<Vec<u32>>) -> Vec<Vec<u32>> { |