Elie_CALI on Fri, 13 Feb 2004 02:22:17 +0100


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

Re: Partition code


great,
and with the slight adaptation below, you save around 25% time more :

bla(n,m,v)=v=concat(v,m);if(!n,print(v),for(i=1,min(m,n),bla(n-i,i,v)))
partitions(n)=for(i=1,n,bla(n-i,i,[]))

Elie CALI.

----- Original Message ----- 
From: "Dr. Robert J. Harley" <harley@argote.ch>
To: <pari-users@list.cr.yp.to>
Sent: Thursday, February 12, 2004 6:19 PM
Subject: Re: Partition code


> Why not something like:
>
> bla(n,m,v,
i)=n-=m;v=concat(v,m);if(!n,print(v),for(i=1,min(m,n),bla(n,i,v)))
> partitions(n, i)=for(i=1,n,bla(n,i,[]))
>
> then:
>
> ? partitions(5)
> [1, 1, 1, 1, 1]
> [2, 1, 1, 1]
> [2, 2, 1]
> [3, 1, 1]
> [3, 2]
> [4, 1]
> [5]
>
>
> R
>