Project Euler Solutions by Ross Marks

<?php
/*****************************
 * ProjectEuler - Problem 26
 * By Ross Marks
 *****************************
 * A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given:
 * 
 * 1/2 =   0.5
 * 1/3 =   0.(3)
 * 1/4 =   0.25
 * 1/5 =   0.2
 * 1/6 =   0.1(6)
 * 1/7 =   0.(142857)
 * 1/8 =   0.125
 * 1/9 =   0.(1)
 * 1/10  =   0.1
 * Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.
 * 
 * Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
 ****************************/

$awns 0;
$awns_repeat 0;

for(
$no 2$no <= 999$no++){
  
$number1 =  bcdiv($no5000); // HAD TO GET THIS RIGHT :/
  
if(findRepeat$number1 ) !== false){
      
$result findRepeat($number1);
      
$leadingNum strstr($number1'.'true);
      
$nonRepeat substr($number1strpos($number1'.') + $result['position']);
      if(
$nonRepeat == '')
          
$nonRepeat '.';

      
$repeat substr($number1,strpos($number1,$nonRepeat) + strlen($nonRepeat), $result['patternSize']);
      
$nonRepeat $nonRepeat == '.' '.' '.'.$nonRepeat;
      
      if(
strlen($repeat) > strlen($awns_repeat)){
        
$awns $no;
        
$awns_repeat $repeat;
        
//echo "New Champ: 1/".$no." - ".strlen($repeat)."\n";
      
}
      
  }
}
echo 
"Answer: $awns";

function 
findRepeat($number){
  
$decimal substr($numberstrpos($number,'.') + );
  
$maxLength strlen($decimal);

  for(
$i =0$i $maxLength$i++){
        
// check repeating no's
        
for($j 2$j <= $maxLength$j++){
          if(
substr($decimal,$i,$j) == substr($decimal$i $j$j) )
            return array(
'position'=>$i,'patternSize'=>$j);
        }
    }
}

?>