Jump to content

Cartesian product of two or more lists: Difference between revisions

add RPL
(add RPL)
Line 4,118:
(4, 2)
</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}}==
"product" is a method of arrays. It takes one or more arrays as argument and results in the Cartesian product:
Line 4,136 ⟶ 4,159:
[]
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">fn cartesian_product(lists: &Vec<Vec<u32>>) -> Vec<Vec<u32>> {
1,151

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.