Dear John, Tnx! But it looks alike. Just add a print command and see how the list "found" increases and the variable k picks up the new added numbers to the list "result".
sage: def posible_values(row,found,maxum): ... result=found ... if row==[]: row=[1] ... if result==[]: result=found=row #Recursion: intended or unintended? ... if max(row)<maxum: ... for k in found: ... print "k=",k,"found", found ... for p in row: ... if k*p <maxum: ... if k*p not in result: result.append(k*p) ... return result ... sage: print posible_values([2,5],[],10) k= 2 found [2, 5] k= 5 found [2, 5, 4, 8] k= 4 found [2, 5, 4, 8] k= 8 found [2, 5, 4, 8] [2, 5, 4, 8] To me this is recursion look-a-like. Roland On 25 aug, 11:22, "John Cremona" <[EMAIL PROTECTED]> wrote: > This does not look recursive to me, since possible_values() does not > call itself. > > John > > 2008/8/25 Rolandb <[EMAIL PROTECTED]>: > > > > > Hi. The following programme looks simple: > > > sage: def posible_values(row,found,maxum): > > ... result=found > > ... if row==[]: row=[1] > > ... if result==[]: result=found=row #Recursion: > > intended or unintended? > > ... if max(row)<maxum: > > ... for k in found: > > ... for p in row: > > ... if k*p <maxum: > > ... if k*p not in result: result.append(k*p) > > ... return result > > ... > > sage: print posible_values([2,3,5],[],100) > > [2, 3, 5, 4, 6, 10, 8, 12, 20, 16, 24, 40, 32, 48, 80, 64, 96, 9, 15, > > 18, 30, 36, 60, 72, 27, 45, 54, 90, 81, 25, 50, 75] > > > To me is the possibility of recursion this way a great plus, but in > > all documents I could not find any reference. So is this intended in > > Python/SAGE or is the above example just bad programming? Roland --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---
