Skip to content

Instantly share code, notes, and snippets.

@olivM
Created November 6, 2013 17:46
Show Gist options
  • Save olivM/7340792 to your computer and use it in GitHub Desktop.
Save olivM/7340792 to your computer and use it in GitHub Desktop.
do the elt is part of a fibonacci ?
function is_fibonacci_element($fib, $count, $limit = 100) {
foreach($fib as $elt)
if ( $count == $elt )
return true;
$idx = count($fib) - 1;
while ($count > $fib[$idx] && $idx < 50) {
$fib[] = $fib[$idx] + $fib[$idx - 1];
$idx = count($fib) - 1;
if ( $count == $fib[$idx] )
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment