49
\$\begingroup\$

Your Task:

Write a program or function to check if a number that is inputted is a Fibonacci number. A Fibonacci number is a number contained in the Fibonacci sequence.

The Fibonacci Sequence is defined as: F(n) = F(n - 1) + F(n - 2)

With the seeds being F(0) = 0 and F(1) = 1.

Input:

A non-negative integer between 0 and 1,000,000,000 that may or may not be a Fibonacci number.

Output:

A truthy/falsy value indicating whether or not the input is a Fibonacci number.

Examples:

0-->truthy
1-->truthy
2-->truthy
12-->falsy

Scoring:

This is , lowest byte count wins.

\$\endgroup\$
  • 2
    \$\begingroup\$ The programming language I'm using only supports numbers up to 9999 (Geometry Dash). Is it okay if I assume that it does support numbers up to 1000000, theoretically? \$\endgroup\$ – MilkyWay90 Jan 26 '19 at 17:51

61 Answers 61

0
\$\begingroup\$

MathGolf, 4 bytes

⌠rf╧

Try it online!

Explanation

We need to increment the input twice before creating the range because we know that \$F_{n+1} \geq n,\forall n \geq 0\$.

⌠      increment twice
 r     range(0, n)
  f    pop a, push fibonacci(a) (maps to the range)
   ╧   pop a, b, a.contains(b) (check if input is in list)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.