ruby - Get all possible permutations of bigger array -
i trying take array of strings ["-", "+", "*"]
, figure out combinations of them given size. possible doing following:
arr = ["-", "+", "*"] perms = arr.permutation(2).to_a # => [["-", "+"], ["-", "*"], ["+", "-"], ["+", "*"], ["*", "-"], ["*", "+"]]
however, want results array bigger given array. e.g., arr.permutations(4).to_arr
. possible?
yes, it's possible.
perms = arr.repeated_permutation(4).to_a
Comments
Post a Comment