JuliaMath / Combinatorics.jl

A combinatorics library for Julia
http://juliamath.github.io/Combinatorics.jl/dev/
Other
215 stars 58 forks source link

Combinations of a set of lengths #120

Open yuvalwas opened 2 years ago

yuvalwas commented 2 years ago

I thought this addition might be handy

combinations(a, T::AbstractVector{<:Integer}) = Iterators.flatten([combinations(a, t) for t in T])
julia> collect(combinations(1:5, 2:3))
20-element Vector{Vector{Int64}}:
 [1, 2]
 [1, 3]
 [1, 4]
 [1, 5]
 ⋮
 [2, 3, 4]
 [2, 3, 5]
 [2, 4, 5]
 [3, 4, 5]