So I have an arbitrary vector of ranges
julia> kthNvals(k) = (1:(2^k)) .- 1;
julia> kthNvals.(1:4)
4-element Vector{UnitRange{Int64}}:
0:1
0:3
0:7
0:15
I need to generate all the vectors where each index is a value in the relevant range.
The hardcoded version looks like this:
julia> l = [[a,b,c,d] for a in 0:1,b in 0:3,c in 0:7,d in 0:15][:]
1024-element Vector{Vector{Int64}}:
[0, 0, 0, 0]
[1, 0, 0, 0]
[0, 1, 0, 0]
[1, 1, 0, 0]
[0, 2, 0, 0]
[1, 2, 0, 0]
[0, 3, 0, 0]
⋮
[0, 1, 7, 15]
[1, 1, 7, 15]
[0, 2, 7, 15]
[1, 2, 7, 15]
[0, 3, 7, 15]
[1, 3, 7, 15]
How do you make this for any kthNvals.(1:k)
?
Would you do it with a recursive macro or some other metaprogramming feature?