Cartesian product of two or more lists: Difference between revisions

m
(→‎{{header|langur}}: updated to use mapX() instead of X())
 
(6 intermediate revisions by 3 users not shown)
Line 1,747:
 
[]</pre>
=={{header|EasyLang}}==
{{trans|Go}}
<syntaxhighlight>
proc cart2 a[] b[] . p[][] .
p[][] = [ ]
for a in a[]
for b in b[]
p[][] &= [ a b ]
.
.
.
cart2 [ 1 2 ] [ 3 4 ] r[][]
print r[][]
cart2 [ 3 4 ] [ 1 2 ] r[][]
print r[][]
cart2 [ 1 2 ] [ ] r[][]
print r[][]
cart2 [ ] [ 1 2 ] r[][]
print r[][]
</syntaxhighlight>
 
=={{header|Erlang}}==
Can do this with list comprehensions.
Line 1,766 ⟶ 1,787:
[{3,1},{3,2},{4,1},{4,2}]
</pre>
 
=={{header|F Sharp|F#}}==
===The Task===
Line 2,006 ⟶ 2,028:
[[File:Fōrmulæ - Cartesian product of two or more lists 03.png]]
 
[[File:Fōrmulæ - Cartesian product of two or more lists 04a04.png]]
 
'''Test case 2.''' With an empty list
Line 2,012 ⟶ 2,034:
[[File:Fōrmulæ - Cartesian product of two or more lists 05.png]]
 
[[File:Fōrmulæ - Empty list a.png]]
 
[[File:Fōrmulæ - Cartesian product of two or more lists 06.png]]
 
[[File:Fōrmulæ - Empty list a.png]]
 
'''Test case 3.''' Extra credit. n-ary cartesian product
Line 2,022 ⟶ 2,044:
[[File:Fōrmulæ - Cartesian product of two or more lists 07.png]]
 
[[File:Fōrmulæ - Cartesian product of two or more lists 08a08.png]]
 
[[File:Fōrmulæ - Cartesian product of two or more lists 09.png]]
 
[[File:Fōrmulæ - Cartesian product of two or more lists 10a10.png]]
 
[[File:Fōrmulæ - Cartesian product of two or more lists 11.png]]
 
[[File:Fōrmulæ - Empty list a.png]]
 
=={{header|Go}}==
Line 2,974 ⟶ 2,996:
</pre>
=={{header|langur}}==
<syntaxhighlight lang="langur">val .X = fn(... .x) { .x }
{{works with|langur|0.8.11}}
 
<syntaxhighlight lang="langur">writeln mapX(f(... .x) .x, [1, 2], [3, 4]) == [[1, 3], [1, 4], [2, 3], [2, 4]]
writeln mapX(f(... .x) .xX, [31, 42], [13, 24]) == [[31, 13], [31, 24], [42, 13], [42, 24]]
writeln mapX(f(...X, .x)[3, .x4], [1, 2]) == [[3, 1], [3, 2]), ==[4, 1], [4, 2]]
writeln mapX(f(...X, .x) .x[1, [2], [1, 2]) == []
writeln mapX(.X, [], [1, 2]) == []
writeln()
 
writeln mapX f(... .x) .xX, [1776, 1789], [7, 12], [4, 14, 23], [0, 1]
writeln()
 
writeln mapX f(... .x) .xX, [1, 2, 3], [30], [500, 100]
writeln()
 
writeln mapX f(... .x) .xX, [1, 2, 3], [], [500, 100]
writeln()</syntaxhighlight>
 
885

edits