Forum: Ruby Re: A question about recursive programming

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Kroeger, Simon (ext) (Guest)
on 2005-12-12 17:45
(Received via mailing list)
>     temp=arr.delete_at(arr.length-1)
>     b=all_sum(arr)+all_sum(arr).collect{|i| i+temp}
> end
> c=[1,2]
> p all_sum(c)
> Error: in `all_sum': stack level too deep (SystemStackError)
> Can anyone give me some advice?


the b= lines doesn't make much sense, you may want to replace
them with return statemants.

Note that delete_at modifies the receiver - the original array
(for this and all other recursions). So it won't work even if
you change the b= to return.


This topic is locked and can not be replied to.