| Bill Allombert on Tue, 06 Feb 2024 17:59:29 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: Looping over ordered partitions |
On Tue, Feb 06, 2024 at 11:46:55AM -0500, Charles Greathouse wrote: > The looping commands force and forpart are very convenient. I have a > problem I was working on which is looking for the smallest vector (in terms > of vecsum) with a certain property. What is the best way to perform such a > search in PARI/GP? > > In my case I have dimension/vector length 11 and sum < 31. (I have an > instance with sum 31 but it's probably not optimal.) > > I can do a forvec, but even forvec(v=vector(11,i,[1,7]), ...) takes a long > time (and spends a lot of time looking at values with sum > 30), and I miss > instances with numbers larger than 7. Or else I can use forpart but then I > need to permute the values (and in my case I definitely have duplicate > values, so naive 11! permutations are wasteful and slow). Use forpart + forperm! forpart(x=30,forperm(x,p,print(p)),,[11,11]) Cheers, Bill.