Start with a guess, then repeatedly update the guess until we're close enough to the desired solution.
use Haldayne\Fox\Improve;
$calculator = new Improve(
function ($guess) { return abs(($guess * $guess) - ($guess + 1)) < .00001; },
function ($guess) { return 1/$guess + 1; }
);
$phi = $calculator(1);
$calculator->getGuessHistory();| package | Haldayne |
|---|
__construct(callable $decide, callable $update)
callableDecides if the guess is good enough. Receives one argument, the current guess.
callableUpdates the guess to a new guess. Receives two arguments: the current guess and the current loop count, in that order.
__invoke(mixed $guess) : mixed
mixedThe initial guess
mixedThe calculated resultgetGuessHistory() : \Haldayne\Boost\Map
\Haldayne\Boost\MapsetMaximumIterations(integer|null $maxIterations) : void
By default, there is no limit.
integernull
$decide
null$guesses
null$maxIterations
null$update
null