From: sanha lee Date: 2005-12-13T00:57:55+09:00 Subject: Re: A question about recursive programming ------=_Part_14454_32665065.1134403066447 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I think that it is better solution def all_sum(arr) return arr if arr.length =3D=3D 1 temp =3D arr[-1] return all_sum(arr[0...-1]) + all_sum(arr[1...-1]).collect {|i| i + temp} end On 12/12/05, Hank Gong wrote: > > I want to calculate all sum possibility of interger array. I know there > are > other non-recursive way to do it. > But when I wrote recursive code to achieve it, I just got error. > > > def all_sum(arr) > b=3Darr if arr.length=3D=3D1 > temp=3Darr.delete_at(arr.length-1) > b=3Dall_sum(arr)+all_sum(arr).collect{|i| i+temp} > end > > c=3D[1,2] > p all_sum(c) > > Error: in `all_sum': stack level too deep (SystemStackError) > > Can anyone give me some advice? > > ------=_Part_14454_32665065.1134403066447--