I have a sorted list of a large number of primes. I want to iterate over combinations of fixed size $n$ in increasing order of their sum. Naturally the standard approach for $n=4$:
$$s_0 = \sum(A, B, C, D)$$ $$s_1 = \sum(A, B, C, E)$$ $$s_2 = \sum(A, B, C, F)$$ $$...$$
will not suffice. Can a strategy be devised to accomplish this?
SortBy[Subsets[Table[Prime[i], {i, 6}], {4}], Total]will do so for the first $6$ primes and $n=4$, and in generalSortBy[Subsets[Table[primelist, {n}], Total]will do so for primes stored inprimelistand combinations of size $n$. – Vincent Tjeng Feb 27 '13 at 14:26