Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sockets - Riyo #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/fibonacci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@
# ....
# e.g. 6th fibonacci number is 8

# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n) where n is the input number
# Space complexity: O(1) the number of variables is constant regardless of size of n
def fibonacci(n)
raise NotImplementedError
fibonacci_num = 0
prior_num = 0
current_num = 1

if !n || n < 0
raise ArgumentError
elsif n == 0 || n == 1
return n
else
(n-1).times do
fibonacci_num = prior_num + current_num
prior_num = current_num
current_num = fibonacci_num
end
return current_num
end
end