hermann on Thu, 07 Sep 2023 16:18:36 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Python combinations() in GP?


On 2023-09-06 17:15, Max Alekseyev wrote:
One can use forsubsets() here:

? forsubset([5,3],s, print(s) )
Vecsmall([1, 2, 3])
Vecsmall([1, 2, 4])
Vecsmall([1, 2, 5])
Vecsmall([1, 3, 4])
Vecsmall([1, 3, 5])
Vecsmall([1, 4, 5])
Vecsmall([2, 3, 4])
Vecsmall([2, 3, 5])
Vecsmall([2, 4, 5])
Vecsmall([3, 4, 5])

Regards,
Max

Thank you, I buy that.
It does not need the final ",2".
And "forsubset" more clearly states what is done.

Part of work in progress Python->GP human transpilation already:

sqtst(L, k, dbg=0)=
{
    assert(#L>=k);
/*
    forvec(s=vector(k,i,[1,#L]),
        LS=concat([sq2(L[x])|x<-s]);
        print(LS),2);
*/
    forsubset([#L,k],s,
        LS=concat([sq2(L[x])|x<-s]);
        print(LS));
...


? \r RSA_numbers_factored.gp
validate(rsa): ✓
? smp1m4[1..4]
%145 = [5, 13, 17, 29]
? sqtst(smp1m4[1..4],3)
[2, 1, 3, 2, 4, 1]
[2, 1, 3, 2, 5, 2]
[2, 1, 4, 1, 5, 2]
[3, 2, 4, 1, 5, 2]
?



Regards,

Hermann.