⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (373 Bytes)
Feature #1218
» fibonacci-iterative.rb
This file computes the nth Fibonacci number using iteration. -
Anonymous, 02/27/2009 12:13 AM
#!/usr/bin/env ruby -w
# compute nth fibonacci number in ruby using iteration.
def
fibonacci
(
n
)
a
,
b
=
0
,
1
n
.
times
do
a
,
b
=
b
,
a
+
b
end
a
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-iterative.rb <integer>"
end
end
« Previous
1
2
3
Next »
(1-1/3)
Loading...