如何在Elixir中获得列表的排列?
例如,对于["a", "b", "c"]
,我希望:
# [["a", "b", "c"], ["a", "c", "b"],
# ["b", "a", "c"], ["b", "c", "a"],
# ["c", "a", "b"], ["c", "b", "a"]]
最佳答案
像这样:
defmodule Permutations do
def of([]) do
[[]]
end
def of(list) do
for h <- list, t <- of(list -- [h]), do: [h | t]
end
end
关于elixir - 如何获得列表的排列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33756396/