在 Wolfram Mathematica 中,有一个名为Permutations
( http://reference.wolfram.com/mathematica/ref/Permutations.html ) 的函数。它可以给出恰好包含 n 个元素的所有排列。
例如:Permutations[{1,2,3,4}, {2}]
给
{{1, 2}, {1, 3}, {1, 4}, {2, 1}, {2, 3}, {2, 4}, {3, 1}, {3, 2}, {3,
4}, {4, 1}, {4, 2}, {4, 3}}
我知道 Matlab 有一个类似的功能perms
,但它只接收一个参数并给出所有可能的排列。有没有其他类似 Mathematica 的函数Permutations[list,{n}]
?</p>