Skip to content

Instantly share code, notes, and snippets.

@netojoaobatista
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netojoaobatista/b82368670da882743479 to your computer and use it in GitHub Desktop.
Save netojoaobatista/b82368670da882743479 to your computer and use it in GitHub Desktop.
$n primeiros elementos da sequência de Fibonacci utilizando a fórmula de Binet
<?php
foreach (call_user_func(function($n) {
for ($x = 1; $x <= $n; ++$x)
yield call_user_func(function($x) {return (1/sqrt(5)) *
(pow((1+sqrt(5))/2,$x) - pow((1-sqrt(5))/2,$x));},
$x);
}, 10) as $n) {
var_dump($n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment