Boost logo

Boost Users :

Subject: [Boost-users] math: combinations of i amongst n elements
From: Hicham Mouline (hicham_at_[hidden])
Date: 2010-10-14 06:39:06


Hi,
Is there an available function to generate all the i-tuples among a sequence of size n (runtime) and 1<= i <=n

For e.g. in a vector of 3 ints 1 2 and 3

we want to get all of the singletons:
1
2
3

all the pairs
1 2
1 3
2 3

and all the triplets
1 2 3

If not and I were to write one (n known at runtime only), what signature should I use?

template <typename iterator>
.... combinations(iterator begin, iterator end)
{
}

what return type would hold all of the singletons, pairs, triplets, ... n-tuples

Perhaps a better signature is
template <typename iterator>
.... combinations(iterator begin, iterator end, int i)
{
}
but then the return type is still not easy to define.

I'm thinking a 2D multi_array where not all the space is used (dim1 size is 2^n and dim2 size is n), and pass it by ref

template <typename iterator>
void combinations(multi_array& out, iterator begin, iterator end)
{
}

regards,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net