Created
August 3, 2014 20:21
-
-
Save flangofas/3fc78963f30adc3f8d3e to your computer and use it in GitHub Desktop.
Fibonacci sequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo fibonacciCode($argv[1]) . PHP_EOL; | |
/** | |
* This function returns the fibonacci sequence | |
* | |
* @param mixed sequence | |
* @return int total | |
*/ | |
function fibonacciCode($sequence = 0) { | |
$total = 0; | |
$i = 0; | |
$a = 0; | |
$b = 1; | |
while ($i < $sequence) { | |
$total = $a + $b; | |
$i++; | |
$a = $b; | |
$b = $total; | |
} | |
return (int)$total; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment