⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (408 Bytes)
Feature #1218
» fibonacci-recursive.rb
This file computes the nth Fibonacci number using recursion. -
Anonymous, 02/27/2009 12:13 AM
#!/usr/bin/env ruby -w
# compute nth fibonacci number in ruby using tail-recursion
def
fibonacci
(
n
)
if
n
==
0
||
n
==
1
n
else
fibonacci
(
n
-
1
)
+
fibonacci
(
n
-
2
)
end
end
if
__FILE__
==
$0
if
(
ARGV
.
length
==
1
)
&&
(
ARGV
.
first
.
to_i
.
is_a?
Integer
)
puts
fibonacci
(
ARGV
.
first
.
to_i
)
else
raise
ArgumentError
,
"Usage: fibonacci-recusive.rb <integer>"
end
end
« Previous
1
2
3
Next »
(2-2/3)
Loading...