Cartesian product of two or more lists: Difference between revisions

Content added Content deleted
(added a solution for Factor)
(Realize in F#)
Line 487: Line 487:
[]</pre>
[]</pre>


=={{header|F Sharp|F#}}==
<lang fsharp>
//Nigel Galloway February 12th., 2018
let cP2 n g = List.map (fun (n,g)->[n;g]) (List.allPairs n g)
</lang>
{{out}}
<pre>
cP [1;2] [3;4] -> [[1; 3]; [1; 4]; [2; 3]; [2; 4]]
cP [3;4] [1;2] -> [[3; 1]; [3; 2]; [4; 1]; [4; 2]]
cP [1;2] [] -> []
cP [] [1;2] -> []
</pre>
=={{header|Factor}}==
=={{header|Factor}}==
<lang Factor>IN: scratchpad { 1 2 } { 3 4 } cartesian-product .
<lang Factor>IN: scratchpad { 1 2 } { 3 4 } cartesian-product .