Jump to content

Cartesian product of two or more lists: Difference between revisions

Erlang version
(Erlang version)
Line 1,471:
 
[]</pre>
=={{header|Erlang}}==
Can do this with list comprehensions.
<syntaxhighlight lang="erlang">
-module(cartesian).
-export([product/2]).
 
product(S1, S2) -> [{A,B} || A <- S1, B <- S2].
</syntaxhighlight>
{{Out}}
<pre>
2> cartesian:product([],[1,2,3]).
[]
3> cartesian:product([1,2,3],[]).
[]
4> cartesian:product([1,2],[3,4]).
[{1,3},{1,4},{2,3},{2,4}]
5> cartesian:product([3,4],[1,2]).
[{3,1},{3,2},{4,1},{4,2}]
</pre>
=={{header|F Sharp|F#}}==
===The Task===
Line 1,505 ⟶ 1,524:
cP [[1;2;3];[];[500;100]] -> []
</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">IN: scratchpad { 1 2 } { 3 4 } cartesian-product .
357

edits

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