ClarkeRubber

UNSW ProgComp: Problem 2 - 2007

Jun 10th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.39 KB | None | 0 0
  1. <?php
  2.  
  3. function number_fits_criterion($a){
  4.     $p = abs(pow($a, 2) - $a - 1);
  5.     if(abs(pow($a, 2) - $a - 1) < pow(10, -14)){
  6.         echo "p^2 - p - 1: $p\n";
  7.         return false;
  8.     }else{
  9.         return true;
  10.     }
  11. }
  12.  
  13. $x = 1;
  14. $y = 1;
  15. $a = 1;
  16.  
  17. while(number_fits_criterion($a)){
  18.     //find next fib
  19.     $temp = $y;
  20.     $y = $y + $x;
  21.     $x = $temp;
  22.     $a = $y/$x;
  23. }
  24. echo "p: $a\n";
  25. echo "Fibonacci Numbers: $x, $y \n";
Advertisement
Add Comment
Please, Sign In to add comment