Permutations of a Set of Elements
I have a Julia snippet which generates all possible 4-tuples with 3 possible elements in each slot:
julia> collect(Iterators.product(ntuple(_ -> 1:3, 4)...))
3×3×3×3 Array{NTuple{4, Int64}, 4}:
[:, :, 1, 1] =
(1, 1, 1, 1) (1, 2, 1, 1) (1, 3, 1, 1)
(2, 1, 1, 1) (2, 2, 1, 1) (2, 3, 1, 1)
(3, 1, 1, 1) (3, 2, 1, 1) (3, 3, 1, 1)
[:, :, 2, 1] =
(1, 1, 2, 1) (1, 2, 2, 1) (1, 3, 2, 1)
(2, 1, 2, 1) (2, 2, 2, 1) (2, 3, 2, 1)
(3, 1, 2, 1) (3, 2, 2, 1) (3, 3, 2, 1)
[:, :, 3, 1] =
(1, 1, 3, 1) (1, 2, 3, 1) (1, 3, 3, 1)
(2, 1, 3, 1) (2, 2, 3, 1) (2, 3, 3, 1)
(3, 1, 3, 1) (3, 2, 3, 1) (3, 3, 3, 1)
[:, :, 1, 2] =
(1, 1, 1, 2) (1, 2, 1, 2) (1, 3, 1, 2)
(2, 1, 1, 2) (2, 2, 1, 2) (2, 3, 1, 2)
(3, 1, 1, 2) (3, 2, 1, 2) (3, 3, 1, 2)
...
Question
How do I modify this code so that instead of using a range 1:3
for the elements, I select elements out of an array, say [1,5]
, or a set Set([1,5])
, with only 2 possibilities?