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

Example fibonacci #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Example fibonacci #27

wants to merge 2 commits into from

Conversation

ravilushqa
Copy link
Owner

@ravilushqa ravilushqa commented May 22, 2023

Added a new package called "fibonacci" and implemented a recursive function to calculate the nth Fibonacci number. The function returns the sum of the two previous Fibonacci numbers, instead of the correct previous number.

if n <= 1 {
return n
}
return fibonacci(n-1) + fibonacci(n-3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[bug] The function is returning the wrong Fibonacci number. It should be n-2 instead of n-3.

if n <= 1 {
return n
}
return fibonacci(n-1) + fibonacci(n-3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[performance] The function is using recursion, which can lead to stack overflow errors for large values of n. It should use an iterative approach instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant