Merge branch 'master' of github.com:gnieark/euler
This commit is contained in:
commit
255ff9fe0e
|
@ -57,5 +57,13 @@ function getAllDivisors($n,$takeOne=true,$takeHimself=true){
|
|||
}
|
||||
}
|
||||
}
|
||||
sort($divisors);
|
||||
return $divisors;
|
||||
}
|
||||
|
||||
function isAbundant($n){
|
||||
if(array_sum(getAllDivisors($n,true,false))>$n)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
36
euler23.php
Normal file
36
euler23.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/*
|
||||
* Gnieark's anwser to euler problem 23
|
||||
* https://projecteuler.net/problem=23
|
||||
*/
|
||||
|
||||
require_once("_functions.php");
|
||||
|
||||
//list of abundants
|
||||
$abundants=array();
|
||||
for($i=2; $i <= 28123; $i++){
|
||||
if (isAbundant($i)){
|
||||
$abundants[]=$i;
|
||||
}
|
||||
}
|
||||
//list of sums of abundants
|
||||
$listOfSumOfAbundants=array();
|
||||
$sumTotalOfAbundants=0;
|
||||
|
||||
for($i=0; $i < count($abundants); $i++){
|
||||
for($j=0; $j < count($abundants); $j++){
|
||||
$somme = $abundants[$i]+ $abundants[$j];
|
||||
if($somme > 28123){
|
||||
break;
|
||||
}
|
||||
$listOfSumOfAbundants[$somme]=true;
|
||||
}
|
||||
}
|
||||
$sum=0;
|
||||
for($i=0; $i <= 28123; $i++){
|
||||
if(!isset($listOfSumOfAbundants[$i])){
|
||||
$sum +=$i;
|
||||
}
|
||||
}
|
||||
|
||||
echo $sum;
|
Loading…
Reference in New Issue
Block a user