function nestedLoop(depth::Integer, n::Integer, symbArr, len::Integer, k::Integer, num_arr)
for i = k:len
num_arr[depth-n+1] = symbArr[i]
n == 1 && println(num_arr)
(n > 1) && nestedLoop(depth, n-1, symbArr, len, i, num_arr)
end
end
function combwithrep(symbArr, n::Integer)
len = length(symbArr)
num_arr = Array(eltype(symbArr),n)
nestedLoop(n, n, symbArr, len, 1, num_arr)
end
@time combwithrep(["+","-","*","/"], 3)
I have some troubles with returning values from elementary recursive function, that computes combinations with repetitions. I can't realize how to commit replacement of println with some return to array in combwithrep() function. I have failed to use tasks for this also. The best result is to obtain iterator over this values, but it is not possible in recursion, isn't it?
I feel that the answer is simple, and i don't understand something about recursion.
Combinationsiterator model to create your ownType,length,start,next, anddonefor an iterator would be a good exercise. - rickhg12hs