Last active
August 29, 2015 14:12
-
-
Save erolg/49f8a44d38eaf27ea5ca to your computer and use it in GitHub Desktop.
Ruby Recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rec i | |
if i==10000 | |
return i | |
else | |
i=i+1 | |
rec(i) | |
end | |
end | |
x = rec(2) | |
puts "#{x}" | |
$>>ruby recursion.rb | |
$>>recursion.rb:2: stack level too deep (SystemStackError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rec i | |
if i==1000 | |
return i | |
else | |
i=i+1 | |
rec(i) | |
end | |
end | |
x = rec(2) | |
puts "#{x}" | |
$>>ruby recursion.rb | |
$>>1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment