Categories
Games History PHP

Fibonacci Series in PHP

What is Fibonacci Series?

Fibonacci series is the sequence where the first two numbers are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two e.g. 0, 1, 1, 2, 3, 5, 8 etc.

The Fibonacci sequence is named after Italian mathematician Fibonacci, although the sequence had been described earlier earlier as Virahanka numbers in Indian mathematics.
Fibonacci numbers are closely related to Lucas numbers in that they are a complementary pair of Lucas sequences.

Fibonacci

The Fibonacci numbers are important in the computational run-time analysis of Euclid’s algorithm to determine the greatest common divisor of two integers: the worst case input for this algorithm is a pair of consecutive Fibonacci numbers.

Recognizing Fibonacci numbers

The question may arise whether a positive integer x is a Fibonacci number or not. This is true if and only if one or both of 5x^{2}+4 or 5x^{2}-4 is a perfect square.

Fibonacci Series without recursion:

<?php
$term = 10;
$num1 = 0;
$num2 = 1;

for ( $i = 0; $i < $term; $i++ ) {
    if ( $i <= 1 ) { 
        $result = $i;
    } else {
        $result = $num1 + $num2;
        $num1 = $num2;
        $num2 = $result;
    }
    echo ' ' . $result;
}
?>

Fibonacci Series using recursion:

<?php
function fibonacci($n)
{
    if ( $n == 0 ) {
        return 0;
    } else if ( $n == 1 ) {
        return 1;
    } else {
        return ( fibonacci( $n - 1 ) + fibonacci( $n - 2 ) );
    }
}

$term = 10;
for ( $i = 0; $i &amp;amp;lt; $term; $i++ ) {
    echo ' '.fibonacci($i);
}
?>

Output: 0 1 1 2 3 5 8 13 21 34

Fun fact

Fibonacci Day is November 23rd, as it has the digits “1, 1, 2, 3” which is part of the sequence. So next Nov 23 let everyone know!

'Coz sharing is caring
Categories
History

Bill Gates forays into rural Bihar

A day after his tryst with Amethi in Uttar Pradesh, Microsoft co- founder Bill Gates got a feel of rural Bihar before he signed a memorandum of cooperation for better healthcare with the state government.

Gates took a ride in a country boat, sat on a charpoy with villagers and walked through the dusty lanes of two underdeveloped hamlets to assess the progress of the health-related programmes-including the pulse polio drive – in the state.
Gates visited Guleria and Tateria villages of Banka district where he talked to women of self-help groups and others to understand their problems.
Gates and his entourage hopped on to the country boat after alighting from a chopper in Khagaria. He lent a patient ear to all the villagers who had huddled around him and enquired about their lifestyle.
According to officials, no resident of Guleria has passed even the matriculation examination and the village does not have any school. Worse, it is considered to be vulnerable to polio.
Gates met health workers and discussed the strategy to combat polio with sustained immunisation drives and effective surveillance programmes.
Gates said he enjoyed his visit to the villages though it was very hot. He added that he was impressed with the progress that the government had made in healthcare.
The Gates Foundation will provide technical and financial support to the state government in its health campaign.
It also seeks to improve the delivery of timely diagnosis and appropriate care for tuberculosis, pneumonia and diarrhoea.
At the outset, such programmes will be initiated in eight districts – Patna, Gopalganj, Begusarai, Samastipur, Khagaria, Saharsa, and East and West Champaran.
Thanking Gates for visiting Bihar, chief minister Nitish Kumar said the state government’s partnership with his foundation would go a long way in bringing about a positive change in the health sector.

'Coz sharing is caring