Answer the question
In order to leave comments, you need to log in
How to determine a perfect square in ruby?
A perfect square is an integer whose square root is an integer.
This is how I check if a number is a Fibonacci number:
def perf_square x
return x == Math.sqrt(x) ** 2
end
perf_square(5 * (num ** 2) + 4) || perf_square(5 * (num ** 2) - 4) ? "IsFibo" : "IsNotFibo"
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question