Last active
April 14, 2016 07:48
-
-
Save fakeheal/ea9c42592db83aad2bba to your computer and use it in GitHub Desktop.
PHP: Highly divisible triangular number (ProjectEuler Problem #12)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function countDivisors($number) | |
{ | |
$count = 0; | |
$sqrtOfNumber = (int)sqrt($number); | |
for($i = 1; $i <= $sqrtOfNumber; $i++) | |
{ | |
if($number % $i == 0) | |
$count += 2; | |
} | |
return sqrt($sqrtOfNumber) == $number ? $count-- : $count; | |
} | |
$n = 0; | |
$i = 1; | |
while(countDivisors($n) < 500){ | |
echo 'Checking: '.$n." \n"; | |
$n += $i; | |
$i++; | |
} | |
echo $n; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/FakeHeal/ea9c42592db83aad2bba#file-php-highly-divisible-triangular-number-php-L9-L14
Need to be refactored ! ! ! ASAP