Re: not homework... something i find an interesting problem

2009-04-21 Thread Trip Technician
Thank you Dave. This does it but slowly. takes every subset of the list a of squares, and then gets a 'partition' that will work, many are very inefficient (with lots of 1s). any hints about how to speed up ? def subset(x): for z in range(1,2**len(x)): q=bin(z) subs=[]

Re: not homework... something i find an interesting problem

2009-04-21 Thread MRAB
Trip Technician wrote: Thank you Dave. This does it but slowly. takes every subset of the list a of squares, and then gets a 'partition' that will work, many are very inefficient (with lots of 1s). any hints about how to speed up ? def subset(x): for z in range(1,2**len(x)):

Re: not homework... something i find an interesting problem

2009-04-21 Thread Trip Technician
On 21 Apr, 14:46, MRAB goo...@mrabarnett.plus.com wrote: Trip Technician wrote: Thank you Dave. This does it but slowly. takes every subset of the list a ofsquares, and then gets a 'partition' that will work, many are very inefficient (with lots of 1s). any hints about how to speed up ?

Re: not homework... something i find an interesting problem

2009-04-21 Thread MRAB
Trip Technician wrote: On 21 Apr, 14:46, MRAB goo...@mrabarnett.plus.com wrote: Trip Technician wrote: Thank you Dave. This does it but slowly. takes every subset of the list a ofsquares, and then gets a 'partition' that will work, many are very inefficient (with lots of 1s). any hints about

Re: not homework... something i find an interesting problem

2009-04-21 Thread bearophileHUGS
MRAB: I think I might have cracked it: ...      print n, sums Nice. If you don't want to use dynamic programming, then add a @memoize decoration before the function, using for example my one: http://code.activestate.com/recipes/466320/ And you will see an interesting speed increase, even if

Re: not homework... something i find an interesting problem

2009-04-21 Thread MRAB
bearophileh...@lycos.com wrote: MRAB: I think I might have cracked it: ... print n, sums Nice. If you don't want to use dynamic programming, then add a @memoize decoration before the function, using for example my one: http://code.activestate.com/recipes/466320/ And you will see an

not homework... something i find an interesting problem

2009-04-18 Thread Trip Technician
although it's not homework (how can i prove that...?) i am still happy with just hints +++ we want to express integers as sums of squares. (repeated squares are allowed) most numbers have one minimal representation e.g. 24=16+4+4, some have two or more e.g. 125 = 121+4 = 100+25 so far I have

Re: not homework... something i find an interesting problem

2009-04-18 Thread Dave Angel
Trip Technician wrote: although it's not homework (how can i prove that...?) i am still happy with just hints +++ we want to express integers as sums of squares. (repeated squares are allowed) most numbers have one minimal representation e.g. 24=16+4+4, some have two or more e.g. 125 = 121+4