0

I want to produce a vector containing all k-element subsets of a second vector. I know that I can do this by applying vecextract with each k-element subset of the natural numbers 1...n to my original vector.

How can I create that vector of subsets of natural numbers, though? I can see that the command forsubset does nearly what I want, but it's an imperative command, not one which creates a vector. So I could use the following function to print a list of vectors: f(n,k)=forsubset([n,k],s,print(s)) but I can only capture them by adding each subset to a List() and then converting the List() to a Vec(). This seems clumsy. Is there a better way to do this, perhaps a totally different one?

Joe
  • 59
  • 6
  • 1
    Please, review my answer to the similar SO question: https://stackoverflow.com/questions/33488332/is-there-a-comfortable-way-to-generate-the-combinations-k-out-of-n-in-pari-gp/33495106#33495106 – Piotr Semenov Sep 05 '22 at 09:51
  • That does seem to answer it well. Thanks! – Joe Sep 06 '22 at 03:45

0 Answers0