* @copyright 2005 John Urquhart Ferguson
* @license http://www.gnu.org/licenses/gpl.html GNU GPL version 2
* @version CVS: $Id:$
* @link http://www.n-e-x.co.uk/doku.php?id=programming:php:fibonacci
* @since File available since Release 0.1
*/
// {{{ phpfib
/**
* This is the main class for the phpfib program.
*
* @category Mathematics
* @package Phpfib
* @author Nexami Engeo
* @copyright 2005 John Urquhart Ferguson
* @license http://www.gnu.org/licenses/gpl.html GNU GPL version 2
* @version CVS: $Id:$
* @link http://www.n-e-x.co.uk/doku.php?id=programming:php:fibonacci
* @since Class available since Release 0.1
*/
//class Phpfib
//{
//}
// }}}
// {{{ helpFib()
/**
* A helper function for fib(). Calculates Fibonacci numbers.
*
* helpFib() is used to speed up the fib() method by preventing repeated
* calculations. In truth, I only ever briefly understood how this works.
* I didn't come up with it, and I understood it just long enough to
* program it in the original Ada version of this program.
*
* @param int $n current Fibonacci index being calculated.
* @param int $k a starting count which should initialy be 1.
* @param BigInt $fibk a starting count which should initialy be 1.
* @param BigInt $fibk1 a starting count which should initialy be 0.
*
* @return BigInt the Fibonacci number of the entertered index.
*
* @static
* @since Method available since Release 0.1
*/
function helpFib($n, $k, $fibk, $fibk1)
{
if ($n == $k) {
return $fibk;
} else {
//return (helpFib($n, $k+1, $fibk->add($fibk1), $fibk));
return (helpFib($n, ($k+1), ($fibk+$fibk1), $fibk));
}
}
// }}}
?>
phpFib
phpFib
Fibonacci number for index '.$_POST['fibIndex'].':
';
echo helpFib($_POST['fibIndex'], 1, 1, 0).'';
}
?>
Enter the Fibonacci index you wish to see the Fibonacci number for.
===== Example of Use =====
Just enter into the form the index of the Fibonacci number you want to know. Then click the calculate button.
===== Assumptions =====
None, but for large Fibonacci indices, the computer may crash from running out of memory. It is also assumed that you have a system capable of running PHP scripts. If not, you can probably find what you need [[http://www.php.net|here]].
--- //[[nex@n-e-x.co.uk|Nexami Engeo]] 2007/07/06 10:36//
~~DISCUSSION~~