"r.e.s." <[EMAIL PROTECTED]> wrote ... > <[EMAIL PROTECTED]> wrote ... >> "r.e.s." <[EMAIL PROTECTED]> 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): >> E=n, >> 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): >> E=n, >> while E*m:n=h(n+1,m-1);E=E[:-1]+(E[-1]>0)*(E[-1]-1,)*n ^ g >> return n >> >> def f(n,m): >> E=n, >> while E*m:n=h(n+1,m-1);E=(E[0]>0)*(E[0]-1,)*n+E[1:] ^ f >> return n >> >> def e(n,m): >> E=[n] >> while E*m:n=h(n+1,m-1);E[:1]=(E[0]>0)*[E[0]-1]*n ^ e >> 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) > > Very instructive! Thank you for the "step-by-step".
I forgot to mention the obvious typos. Thanks again. -- http://mail.python.org/mailman/listinfo/python-list