This commit is contained in:
gnieark 2015-11-15 19:42:49 +01:00
parent 413673dd54
commit 6f995bb87d

29
euler12.php Normal file
View File

@ -0,0 +1,29 @@
<?php
/*
* Gnieark's anwser to euler problem 12
* https://projecteuler.net/problem=12
*/
$triangleNumber=1;
$triangleValue=1;
while(countDivisors($triangleValue)<500){
//echo $triangleValue.":".countDivisors($triangleValue)."\n";
$triangleNumber++;
$triangleValue+=$triangleNumber;
}
echo $triangleValue;
function countDivisors($number){
$right=$number;
$i=1;
$counter=0;
while($i<=$right){
if(fmod($number,$i)==0){
$right=$number/$i; //increase algo speed
$counter++;
}
$i++;
}
return $counter *2 ;
}