Skip to content

implementing is_Fibonacci function differently #1

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

Open
wants to merge 1 commit into
base: main
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
19 changes: 10 additions & 9 deletions Fibonacci-number-detector-function/function.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import math

# A utility function that returns true if x is perfect square
def isPerfectSquare(x):
s = int(math.sqrt(x))
return s*s == x

# Returns true if n is a Fibonacci Number, else false
def isFibonacci(n):
s = []
a, b = 0, 1
while a <= n:
s = [a]
a, b = b, a + b
if n in s:
return True
else:
return False
# n is Fibonacci iff (5*n*n + 4 or 5*n*n - 4) is a perfect square
return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n - 4)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy