예제 #1
0
function fibo($n)
{
    //  return 1 ? 1 : 2;
    //  echo "\$n is: $n\n";
    $n = (int) $n;
    return $n < 2 ? 1 : fibo($n - 2) + fibo($n - 1);
}
예제 #2
0
/**
 * A Fibonacci generator!!!
 *
 * This is a recursive implementation. Very slow on PHP, and MUCH faster
 * when compiled.
 *
 * We only need this function as a fallback, since we're compiling with the IR,
 * this won't be touched until the benchmark.
 *
 * @param int $n The number of the sequence to generate
 *
 * @return int the fibonacci number!
 */
function fibo($n)
{
    if ($n < 2) {
        return 1;
    }
    return fibo($n - 1) + fibo($n - 2);
}
예제 #3
0
/**
 * @ProfileGroup("fibo")
 * @ProfileCaption("fibo of #1")
 */
function fibo($x)
{
    if ($x <= 1) {
        return $x;
    } else {
        return fibo($x - 1) + fibo($x - 2);
    }
}
예제 #4
0
function fibos($n, $m = 1)
{
    if ($n < $m) {
        return;
    }
    echo fibo($m), ' ';
    return fibos($n, $m + 1);
}
예제 #5
0
파일: Task_1.php 프로젝트: Just-Man/PHP
function fibo($n)
{
    if ($n <= 0) {
        return 0;
    }
    if ($n == 1) {
        return 1;
    }
    return fibo($n - 1) + fibo($n - 2);
}
예제 #6
0
파일: dz2.php 프로젝트: AnnaOzer/shp-php1
function fibo($n)
{
    $n = (int) $n;
    // приведение типа к int
    if ($n <= 2) {
        return 1;
    } else {
        return fibo($n - 1) + fibo($n - 2);
    }
}
예제 #7
0
파일: fibo.php 프로젝트: NideXTC/CoursYNov
function fibo($start, $next, $limit)
{
    global $a;
    if ($limit <= $a) {
        return false;
    }
    $a++;
    echo $start + $next . PHP_EOL;
    fibo($next, $start + $next, $limit);
}
예제 #8
0
파일: test.php 프로젝트: dw4dev/Phalanger
 static function fibo()
 {
     Timing::Start("fibo.php");
     fibo(30);
     Timing::Stop();
 }
예제 #9
0
파일: mixedbag.php 프로젝트: badlamer/hhvm
function main_function()
{
    ackermann(2);
    ary(500);
    ary2(500);
    ary3(5);
    fibo(13);
    hash1(100);
    hash2(20);
    heapsort(200);
    matrix(3);
    nestedloop(3);
    sieve(1);
    strcat(80);
    binary_trees(3);
    fannkuch(6);
}
예제 #10
0
파일: bench.php 프로젝트: cefalo19/php-src
$t = end_test($t, "simpleucall");
simpleudcall();
$t = end_test($t, "simpleudcall");
mandel();
$t = end_test($t, "mandel");
mandel2();
$t = end_test($t, "mandel2");
ackermann(7);
$t = end_test($t, "ackermann(7)");
ary(50000);
$t = end_test($t, "ary(50000)");
ary2(50000);
$t = end_test($t, "ary2(50000)");
ary3(2000);
$t = end_test($t, "ary3(2000)");
fibo(30);
$t = end_test($t, "fibo(30)");
hash1(50000);
$t = end_test($t, "hash1(50000)");
hash2(500);
$t = end_test($t, "hash2(500)");
heapsort(20000);
$t = end_test($t, "heapsort(20000)");
matrix(20);
$t = end_test($t, "matrix(20)");
nestedloop(12);
$t = end_test($t, "nestedloop(12)");
sieve(30);
$t = end_test($t, "sieve(30)");
strcat(200000);
$t = end_test($t, "strcat(200000)");
예제 #11
0
<?php

//nie wiedzialem jak to rozwiazac, wydaje mi sie ze wynik funkcji jest bledny
function fibo($n)
{
    if ($n <= 2) {
        return 1;
    } else {
        $a = 1;
        $b = 1;
        $c = 0;
        for ($i = 0; $i < $n - 2; $i++) {
            $c = $a + $b;
            $a = $b;
            $b = $c;
        }
        echo "{$n}, {$a}, {$b}";
    }
}
fibo(8);
예제 #12
0
파일: index.php 프로젝트: brslv/code
<?php

// Write a function that computes the list of the first 100 Fibonacci numbers.
// By definition, the first two numbers in the Fibonacci sequence are 0 and 1,
// and each subsequent number is the sum of the previous two.
// As an example, here are the first 10 Fibonnaci numbers:
// 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34.
function fibo($n)
{
    $fibo = [];
    $a = 0;
    $b = 1;
    $index = 1;
    while ($index <= $n) {
        $c = $a + $b;
        $a = $b;
        $b = $c;
        $fibo[] = $c;
        $index++;
    }
    return $fibo;
}
$result = fibo(100);
echo implode(', ', $result);
예제 #13
0
<?php

#1000-digit Fibonacci number - Problem 25
ini_set('max_execution_time', 600);
$time_start = microtime(true);
//////////////////////////////////////////////////////
$a = 1;
$b = 2;
function fibo($n, &$a, &$b)
{
    $f = bcadd($a, $b);
    $a = $b;
    $b = $f;
    return $f;
}
for ($i = 4; $i <= 100000000; $i++) {
    $f = fibo($i, $a, $b);
    if (strlen($f) >= 1000) {
        echo "Fn is {$i}";
        break;
    }
}
//////////////////////////////////////////////////////////////////////
// End of execution time calculation
$time_end = microtime(true);
$execution_time = $time_end - $time_start;
//total execution time
/////////////////////////////////////////////////////////////////////
//Below Outputs the execution time in seconds
echo '<br /><br /><b>Total Execution Time:</b> ' . $execution_time . ' seconds';
예제 #14
0
파일: fibo.php 프로젝트: michaelprem/phc
function fibo($n)
{
    return $n < 2 ? 1 : fibo($n - 2) + fibo($n - 1);
}
예제 #15
0
<?php

//echo"Enter the number to get no. of fibonacci series";
function fibo($num)
{
    $num1 = 0;
    $num2 = 1;
    if ($num == 0) {
        return 0;
    }
    if ($num == 1) {
        echo "{$num2}";
    }
    for ($i = 0; $i <= $num; $i++) {
        $sum = $num1 + $num2;
        $num1 = $num2;
        $num2 = $sum;
        echo $sum . '</br>';
    }
}
echo fibo(6);
예제 #16
0
function main_function()
{
    for ($i = 0; $i < 100; ++$i) {
        ackermann(4);
        ary(50000);
        ary2(50000);
        ary3(100);
        fibo(23);
        hash1(10000);
        hash2(200);
        heapsort(2000);
        matrix(3);
        nestedloop(8);
        sieve(5);
        strcat(80000);
        binary_trees(7);
        fannkuch(6);
    }
}
예제 #17
0
/**
 * Created by PhpStorm.
 * User: antonio
 * Date: 30/07/15
 * Time: 21:30
 * Crie uma pasta “p2_exercicio7” e um arquivo index.php. Dentro dele crie um programa para mostrar a sequência fibonacci até o 100º elemento,
 * para isso, crie uma função fibonacci que deverá receber o índice do elemento e a função irá calcular o número correspondente daquele índice.
 */
function fibo($n)
{
    return $n < 2 ? $n : fibo($n - 1) + fibo($n - 2);
}
예제 #18
0
파일: fibonachi.php 프로젝트: Overfinch/oop
<?php

function fibo($limit)
{
    $temp1 = 1;
    // тут хранится прошое число
    $temp2 = 0;
    // тут хранится позапрошое число
    for ($i = 0; $i < $limit; $i++) {
        $result = $temp1 + $temp2;
        // сума прошлого и позапрошлого числа
        print $result . "<br>";
        $temp2 = $temp1;
        // записыаем то число которое было слогаемым для нынешней итерации, в "позапрошлое" для следующей
        $temp1 = $result;
        // записываем число которое было результатом для нынешней итерации, в "прошлое" для следуещей
    }
}
fibo(10);
예제 #19
0
파일: fibo.php 프로젝트: michaelprem/phc
    return $t['sec'] + $t['usec'] / 1000000;
}
function start_test()
{
    ob_start();
    return getmicrotime();
}
function end_test($start, $name)
{
    global $total;
    $end = getmicrotime();
    ob_end_clean();
    $total += $end - $start;
    $num = number_format($end - $start, 3);
    $pad = str_repeat(" ", 24 - strlen($name) - strlen($num));
    echo $name . $pad . $num . "\n";
    ob_start();
    return getmicrotime();
}
function total()
{
    global $total;
    $pad = str_repeat("-", 24);
    echo $pad . "\n";
    $num = number_format($total, 3);
    $pad = str_repeat(" ", 24 - strlen("Total") - strlen($num));
    echo "Total" . $pad . $num . "\n";
}
$t0 = $t = start_test();
fibo();
$t = end_test($t, "fibo(30)");
예제 #20
0
파일: common.php 프로젝트: nextop/forp-ui
/**
 * @ProfileGroup("Fibo Group")
 * @ProfileCaption("Caption of fibo, value #1 #1 #1 #1")
 * @param type $x
 * @return int
 */
function fibo($x)
{
    if ($x < 2) {
        return 1;
    } else {
        return fibo($x - 1) + fibo($x - 2);
    }
}
예제 #21
0
<?php

function fibo_r($n)
{
    return $n < 2 ? 1 : fibo_r($n - 2) + fibo_r($n - 1);
}
function fibo($n)
{
    $r = fibo_r($n);
    print "{$r}\n";
}
// PHP takes ages to run this. Original was 30.
fibo(4);