Given a set of characters and a number I’m trying to generate all possible sequences. For example, given
“ACTG” to generate all possible sequences of length 2 I could do.
letters = "ACTG"
for i in letters
for j in letters
print(i,j," ")
end
end
AA AC AT AG CA CC CT CG TA TC TT TG GA GC GT GG
And say n = 3 I could do
for i in letters
for j in letters
for k in letters
print(i,j,k," ")
end
end
end
My question is how can I do this with Julia’s metaprogramming?
function permutations(array,n)
exp = quote
l = []
@nloops $n i _ -> 1:length($array) begin
idx =[@ntuple($n,i)...]
push!(l,$array[idx])
end
l
end
eval(exp)
end