mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-01-17 15:18:13 +01:00
add ExponentialSearch Algorithm
This commit is contained in:
parent
05387454b6
commit
627564b686
4
.gitignore
vendored
4
.gitignore
vendored
@ -4,4 +4,6 @@
|
||||
.phan
|
||||
composer.lock
|
||||
|
||||
.phpunit.result.cache
|
||||
.phpunit.result.cache
|
||||
|
||||
GITING.md
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Function to find nth number in Fibonacci sequence.
|
||||
* Uses a version of memoization and runs very fast!
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param int $n position to check
|
||||
* @param array $m array to store solved trees
|
||||
*/
|
||||
function fibonacciPosition(int $n, array &$m = [])
|
||||
{
|
||||
if(isset($m[$n])) return $m[$n];
|
||||
if($n < 2) return $n;
|
||||
|
||||
$m[$n] = fibonacciPosition($n - 1, $m) + fibonacciPosition($n - 2, $m);
|
||||
|
||||
return $m[$n];
|
||||
|
||||
}
|
||||
|
||||
print fibonacciPosition(59);
|
Loading…
x
Reference in New Issue
Block a user