Skip to content

Instantly share code, notes, and snippets.

@cnocon
Created October 26, 2013 21:46
Show Gist options
  • Select an option

  • Save cnocon/7174944 to your computer and use it in GitHub Desktop.

Select an option

Save cnocon/7174944 to your computer and use it in GitHub Desktop.
Non-Iterative, Non-Recursive Solution for Identifying Whether a Number is a Fibonacci Number
def is_fibonacci?(i)
n1 = (5*i**2 + 4)**0.5
n2 = (5*i**2 - 4)**0.5
n1 % 1 == 0 || n2 % 1 == 0 ? true : false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment