I think this does the right thing. One question is when generalizing to higher dimensions, are (1,1,2) and (1,2,1) symmetric? Also maybe the logic of the asymmetric flag is revered...
permutations(items, order::Int; asymmetric::Bool = false) = sort(permutations([], items, order, asymmetric))
function permutations(partical_perm::Array{Any,1}, items, order::Int, asymmetric::Bool)
if order == 0
return [tuple(partical_perm...)]
else
perms = []
for item in items
if !asymmetric && length(partical_perm) > 0
if partical_perm[end] < item
continue
end
end
perm = permutations(vcat([item], partical_perm), items, order-1, asymmetric)
append!(perms, perm)
end
return perms
end
end
I think this does the right thing. One question is when generalizing to higher dimensions, are
(1,1,2)
and(1,2,1)
symmetric? Also maybe the logic of theasymmetric
flag is revered...