当前位置: 首页>>代码示例>>PHP>>正文


PHP fibonacci函数代码示例

本文整理汇总了PHP中fibonacci函数的典型用法代码示例。如果您正苦于以下问题:PHP fibonacci函数的具体用法?PHP fibonacci怎么用?PHP fibonacci使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fibonacci函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fibonacci

function fibonacci($number)
{
    if ($number <= 2) {
        return 1;
    }
    return fibonacci($number - 1) + fibonacci($number - 2);
}
开发者ID:YuraMalahov,项目名称:algorithms,代码行数:7,代码来源:fibonacci.php

示例2: fibonacci

function fibonacci($n)
{
    if ($n <= 1) {
        return $n;
    } else {
        return fibonacci($n - 1) + fibonacci($n - 2);
    }
}
开发者ID:iml-it,项目名称:compiler-example,代码行数:8,代码来源:complicated_script.php

示例3: run

 public function run()
 {
     $r = 0;
     for ($n = 1; $n <= 5; $n++) {
         $r += fibonacci($n);
     }
 }
开发者ID:lihuibin,项目名称:jphp,代码行数:7,代码来源:FibonacciBenchmark.php

示例4: fibonacci

/**
 * Sequência de Fibonacci
 *
 * Autor:
 *   ?
 * Colaborador:
 *   Felipe Djinn <felipe@felipedjinn.com.br>
 * Tipo:
 *   math
 * Descrição:
 *   Na matemática, os Números de Fibonacci são uma sequência definida como recursiva.
 *   O algoritmo recursivo que define a série aplica-se, na prática, conforme a regra sugere: 
 *   começa-se a série com 0 e 1; a seguir, obtém-se o próximo número de Fibonacci somando-se 
 *   os dois anteriores e, assim, sucessiva e infinitamente.
 * Complexidade:
 *   F(n) = {
 *      0 se n = 0;
 *      1 se n = 1;
 *      F(n - 1) + F(n - 2)
 *   }
 * Referências:
 *   http://pt.wikipedia.org/wiki/N%C3%BAmero_de_Fibonacci
 */
function fibonacci($n)
{
    if ($n < 2) {
        return $n;
    }
    return fibonacci($n - 1) + fibonacci($n - 2);
}
开发者ID:pedrohenrique13,项目名称:1001,代码行数:30,代码来源:fibonacci.php

示例5: fibonacci

function fibonacci($n)
{
    if ($n == 0 || $n == 1) {
        return $n;
    }
    return fibonacci($n - 2) + fibonacci($n - 1);
}
开发者ID:raynaldmo,项目名称:php-education,代码行数:7,代码来源:fibonacci_recursion.php

示例6: fibonacci

function fibonacci($n)
{
    if ($n === 1 || $n === 2) {
        return 1;
    }
    return fibonacci($n - 1) + fibonacci($n - 2);
}
开发者ID:bogdanbuciu,项目名称:invendium-practice,代码行数:7,代码来源:php_ex14.php

示例7: fibonacci

function fibonacci($n)
{
    if ($n < 4) {
        return 1;
    }
    //in a fib3 the sum of the first three numbers constitutes the sum
    return fibonacci($n - 1) + fibonacci($n - 2) + fibonacci($n - 3);
}
开发者ID:kemeikitur,项目名称:fibonicca-and-prime-numbers,代码行数:8,代码来源:fibonnicathirdterm.php

示例8: testPositiveNumberFibonnacci

 public function testPositiveNumberFibonnacci()
 {
     // Given the next order
     // Keys     [0..14]
     // Values   [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377]
     $this->assertEquals(fibonacci(14), 377);
     $this->assertEquals(fibonacci_iterative(14), 377);
 }
开发者ID:marius-rizac,项目名称:Algorithm-Implementations,代码行数:8,代码来源:fibonacci_test.php

示例9: fibonacci

function fibonacci($x)
{
    if ($x <= 2) {
        return 1;
    } else {
        return fibonacci($x - 1) + fibonacci($x - 2);
    }
}
开发者ID:cosim,项目名称:fuzuli,代码行数:8,代码来源:fibonacci.php

示例10: fibonacci

function fibonacci($n)
{
    if ($n < 3) {
        return 1;
    } else {
        return fibonacci($n - 1) + fibonacci($n - 2);
    }
}
开发者ID:RuslanKoval,项目名称:github_dz_1,代码行数:8,代码来源:index.php

示例11: fibonacci

function fibonacci($n)
{
    if ($n < 2) {
        return $n . "<br>";
    } else {
        return fibonacci($n - 1) + fibonacci($n - 2);
    }
}
开发者ID:ferbj,项目名称:exercisesphp,代码行数:8,代码来源:ejercicio01.php

示例12: fibonacci

function fibonacci($end)
{
    $number = null;
    if ($end <= 1) {
        echo $end;
    } else {
        $number = fibonacci($end - 2) + fibonacci($end - 1);
    }
    echo $number . ' ';
}
开发者ID:Just-Man,项目名称:PHP,代码行数:10,代码来源:FibonachiNumbers.php

示例13: fibonacci

function fibonacci($n)
{
    if ($n == 0) {
        return 0;
    }
    if ($n <= 2) {
        return 1;
    }
    return fibonacci($n - 1) + fibonacci($n - 2);
}
开发者ID:elzup,项目名称:CodeIQ,代码行数:10,代码来源:train.php

示例14: fibonacci

function fibonacci($term_1, $term_2)
{
    $sum = $term_1 + $term_2;
    if ($sum < 4000000) {
        if ($sum % 2 == 0) {
            $GLOBALS['sum'] += $sum;
        }
        fibonacci($term_2, $sum);
    }
}
开发者ID:zachlite,项目名称:project-euler,代码行数:10,代码来源:problem_2.php

示例15: fibonacci

function fibonacci($num)
{
    if ($num == 0) {
        return 0;
    } else {
        if ($num == 1) {
            return 1;
        } else {
            return fibonacci($num - 1) + fibonacci($num - 2);
        }
    }
}
开发者ID:beeher,项目名称:hw,代码行数:12,代码来源:fibonacci2.php


注:本文中的fibonacci函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。