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

lj fib brute force #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
7 changes: 7 additions & 0 deletions .idea/.rakeTasks

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/fibonacci.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

302 changes: 302 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion lib/fibonacci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,30 @@
# ....
# e.g. 6th fibonacci number is 8
def fibonacci(n)
raise NotImplementedError
if n.nil? || n < 0
raise ArgumentError
# sum the two previous numbers in sequence to the provided number
elsif n > 1
x = 1
fiba = 0
fibb = 1
while x < n
fibb = fiba + fibb
fiba = fibb - fiba
x += 1
end
elsif
fibb = n
end


return fibb
end

# sum the two previous numbers in sequence to the provided number
fibonacci(12)

# Time complexity is linear, as the while loop will run n times
# Space complexity is constant as there will always be 3 variables,
# one to store the iterator, one to store the first fibbonacci number
# and one to store the second in the sequence