コード例 #1
0
ファイル: index.php プロジェクト: vitorgja/Fatec-rl
 public function resultado()
 {
     if ($this->fib == '') {
         "Não foi digitado um Numero";
     } else {
         require_once 'fibonacci.php';
         $f = new Fibonacci();
         $data['fibonacci'] = $f->fibonacci($this->fib);
         require_once 'view/resultado.php';
     }
 }
コード例 #2
0
ファイル: Fibonacci.php プロジェクト: zekiunal/fibonacci
 /**
  * @param integer $n
  *
  * @return integer
  */
 public static function get($n)
 {
     if (isset(self::$cache[$n])) {
         return self::$cache[$n];
     }
     self::validate($n);
     foreach (Fibonacci::sequence($n + 1) as $key => $number) {
         self::$cache[$key] = $number;
     }
     return self::$cache[$n];
 }
コード例 #3
0
 /**
  * Calculate the Fibonacci number of the given integer.
  * @param int n If n <= 0 then 0 is assumed.
  * @return int Fibonacci number.
  */
 public static function fib($n)
 {
     if ($n <= 0) {
         return 0;
     } else {
         if ($n == 1) {
             return 1;
         } else {
             return Fibonacci::fib($n - 1) + Fibonacci::fib($n - 2);
         }
     }
 }
コード例 #4
0
<?php

class Fibonacci
{
    private $f = array(0, 1, 1);
    public function get($n)
    {
        if (!isset($this->f[$n])) {
            $this->f[$n] = $this->get($n - 1) + $this->get($n - 2);
        }
        return $this->f[$n];
    }
}
$fibonacciNumbers = new Fibonacci();
foreach (file($argv[1]) as $line) {
    echo $fibonacciNumbers->get(trim($line)) . "\n";
}
コード例 #5
0
ファイル: index.php プロジェクト: vitorgja/Fatec-rl
<?php

// inclui no documento a pagina que contem a Classe Fibonacci
require_once 'fibonacci.php';
// Instancia um novo Objeto da Classe Fibonacci
$fibonacci = new Fibonacci();
// verifica se chego o numero  para que
//possa ser chamado o metodo "fibonacci(numero)" da Classe Fibonacci
$numero = isset($_POST['numero']) ? $_POST['numero'] : '';
// mostra na tela o resultado do metodo "fibonacci(numero)" da Classe Fibonacci
echo $fibonacci->fibonacci($numero);
コード例 #6
0
ファイル: FibonacciTest.php プロジェクト: zekiunal/fibonacci
 /**
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage Application only accepts integers. Input was: string
  */
 public function testInvalidArgumentNotInteger()
 {
     Fibonacci::get("string");
 }
コード例 #7
0
ファイル: index.php プロジェクト: vitorgja/Fatec-rl
<?php

require_once 'fibonacci.php';
$fibonacci = new Fibonacci();
// N1 recebe um numero pela URL
$numero = isset($_GET['numero']) ? $_GET['numero'] : '';
echo $fibonacci->fibonacci($this->fib);
コード例 #8
0
    }
    public function key()
    {
        return $this->key;
    }
    public function next()
    {
        if ($this->value === 0) {
            $this->value = 1;
        } else {
            $old = $this->value;
            $this->value += $this->sum;
            $this->sum = $old;
        }
        $this->key++;
    }
    public function valid()
    {
        return $this->value < PHP_INT_MAX;
    }
}
// print the Fibonacci numbers until PHP_INT_MAX
foreach ($test = new Fibonacci() as $key => $value) {
    printf("%d) %d\n", $key, $value);
}
// print the first 10 Fibonacci's numbers
$num = new Fibonacci();
for ($i = 0; $i < 10; $i++) {
    printf("%d) %d\n", $i, $num->current());
    $num->next();
}
コード例 #9
0
 * Copyright 2015 The University of Edinburgh.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
namespace Maths;

require "Fibonacci.php";
/**
 * Print usage information.
 */
function printUsage()
{
    print "Usage: php FibonacciProgram.php N\n";
    print "  where N >= 0\n";
}
if (count($argv) < 2) {
    printUsage();
} else {
    print Fibonacci::fib($argv[1]);
    print "\n";
}
コード例 #10
0
ファイル: soma50fibonacci.php プロジェクト: dhyego/sexlog
        $this->num_termos = $n;
    }
    /**
     * Retorna o enésimo termo da sequência de Fibonacci
     */
    public function termo($n)
    {
        if ($n > $this->num_termos) {
            $this->calcula($n);
        }
        return $this->termos[$n - 1];
    }
    /**
     * Retorna a soma dos enésimos termos da sequência de Fibonacci
     */
    public function soma($n)
    {
        return $this->termo($n + 2) - 1;
    }
    /**
     * Imprime os termos calculados
     */
    private function debug()
    {
        for ($i = 0; $i < $this->num_termos; $i++) {
            echo "Posição {$i} valor " . $this->termos[$i] . "<br>";
        }
    }
}
$F = new Fibonacci();
echo "Soma dos 50 primeiros termos da sequência de Fibonacci -> <a href=\"https://sexlog.com/prova_" . $F->soma(50) . "\">" . $F->soma(50) . "</a>";
コード例 #11
0
 /** Test Fibonacci::fib(30). */
 public function testFib30()
 {
     $this->assertEquals(832040, Fibonacci::fib(30));
 }
コード例 #12
0
    public function current()
    {
        return $this->value;
    }
    public function key()
    {
        return $this->key;
    }
    public function next()
    {
        if ($this->value === 0) {
            $this->value = 1;
        } else {
            $old = $this->value;
            $this->value += $this->sum;
            $this->sum = $old;
        }
        $this->key++;
    }
    public function valid()
    {
        return true;
    }
}
// check the first 10 Fibonacci's numbers
$num = new Fibonacci();
$correct = array(0, 1, 1, 2, 3, 5, 8, 13, 21, 34);
for ($i = 0; $i < 10; $i++) {
    printf("%s<br>", $num->current() === $correct[$i] ? 'OK ' : 'ERROR');
    $num->next();
}
コード例 #13
0
	<body>
		<div class="cabecalho">
				<span id="imagem-cabecalho-1"></span>
				<span id="titulo">Teste da classe Fibonacci</span>
				<span id="imagem-cabecalho-1"></span>
		</div>
            
                <a href="http://pt.wikipedia.org/wiki/N%C3%BAmero_de_Fibonacci">Saiba mais sobre a constante</a>
		
		<div class="corpo">
				<?php 
//incluíndo o arquivo da classe.
include_once 'classes/fibonacci.class.php';
//Instanciando um objeto.
$objetoFibonacci = new Fibonacci();
//echo $objetoFibonacci->fibonacciRecursive(5);
//Usa a função que mostra N termos (um número grande - maior do que 20- acarreta lentidão)
//Um valor como 30, por exemplo, pode levar mais de 60 segundos.
echo $objetoFibonacci->calculaNTermos(5);
//Apresenta erro pois o valor para calcular um termo tem que ser positivo.
echo $objetoFibonacci->fibonacciRecursive(-2);
//Verificando os tempos de início e fim do cálculo
echo 'Tempo incial: ' . $objetoFibonacci->getInicialTimeExecution() . '<br/>';
echo 'Tempo final: ' . $objetoFibonacci->getFinalTimeExecution();
?>
		</div>
		
		<div class="footer">
			<div class="html-validator">
				<p>
コード例 #14
0
ファイル: testdrive.php プロジェクト: bamzy/huco618
<?php

/**
 * Created by PhpStorm.
 * User: bamdad
 * Date: 2/3/2016
 * Time: 9:02 PM
 */
include_once './autoload.php';
$fibo = new Fibonacci();
$fibo->sequence(10);
コード例 #15
0
ファイル: fibonacci.php プロジェクト: scottjparker21/hw
    function generator()
    {
        if ($this->n == 0) {
            echo "exit if";
            print_r($this->array);
            return 0;
        }
        $this->a = $this->b + $this->c;
        $this->b = $this->c;
        $this->c = $this->a;
        $this->array[$this->counter] = $this->b;
        if ($this->b != 0) {
            $this->counter++;
        }
        $this->n = $this->n - 1;
        return $this->generator();
    }
}
$fibonacci = new Fibonacci(5, 9);
echo $fibonacci->generator();
// function fib($a,$n) {
// 		$c = 0;
// 		$b = $a;
// 	for($i = 0; $i < $n; $i++) {
// 			$a = $b + $c;
// 			$b = $c;
// 			$c = $a;
// 			echo  $i . " number in fib sequence  = " . $b . "\n";
// 	}
// }
// fib(5,9);