获取更大数组的所有可能排列

Get all possible permutations of bigger array

我正在尝试获取一个字符串数组 ["-", "+", "*"] 并计算出它们在给定大小下的所有组合。这可以通过执行以下操作来实现:

arr = ["-", "+", "*"]
perms = arr.permutation(2).to_a
# => [["-", "+"], ["-", "*"], ["+", "-"], ["+", "*"], ["*", "-"], ["*", "+"]]

但是,我想获得比给定数组更大的数组的结果。例如,arr.permutations(4).to_arr。这可能吗?

不,不是通过任何内置库或统计方法。

组合和排列方法实现标准概率论函数。也就是说,"A things taken B at a time." 您不能使用这些标准方法创建组合或排列来获取比集合中实际拥有的更多 "things"。

是的,有可能。

perms = arr.repeated_permutation(4).to_a