Can this program be shortened? Measuring program-length?

wolfram.hinderer at wolfram.hinderer at
Thu Jul 10 23:59:13 CEST 2008

On 10 Jul., 21:57, "r.e.s." <r_e_s... at> wrote:
> Can the following program be shortened? ...
> def h(n,m):
>  E=n,
>  while (E!=())*m>0:n=h(n+1,m-1);E=E[:-1]+(E[-1]>0)*(E[-1]-1,)*n
>  return n
> h(9,9)

Some ideas...

# h is your version
def h(n,m):
 while (E!=())*m>0:n=h(n+1,m-1);E=E[:-1]+(E[-1]>0)*(E[-1]-1,)*n
 return n

def g(n,m):
 while E*m:n=h(n+1,m-1);E=E[:-1]+(E[-1]>0)*(E[-1]-1,)*n
 return n

def f(n,m):
 while E*m:n=h(n+1,m-1);E=(E[0]>0)*(E[0]-1,)*n+E[1:]
 return n

def e(n,m):
 while E*m:n=h(n+1,m-1);E[:1]=(E[0]>0)*[E[0]-1]*n
 return n

# some tests
print h(1,1), h(2,1), h(0,2)
print g(1,1), g(2,1), g(0,2)
print f(1,1), f(2,1), f(0,2)
print e(1,1), e(2,1), e(0,2)

More information about the Python-list mailing list