H
Hank Gong
------=_Part_12991_15632434.1134400466601
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
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_12991_15632434.1134400466601--
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
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_12991_15632434.1134400466601--