Skip to content

Instantly share code, notes, and snippets.

@bhenry
Forked from anonymous/20.php
Created May 1, 2012 13:25
Show Gist options
  • Save bhenry/2567883 to your computer and use it in GitHub Desktop.
Save bhenry/2567883 to your computer and use it in GitHub Desktop.
euler 20
<?php
function facto($x){
$r = 1;
for($i=$x;$i>1;$i--){
$r *= $i;
}
return $r;
}
set_time_limit(120);
//error_reporting(0);
$n = nfact(100);
function nfact($x)
{
$result = 1;
if($x >1){
for($i=2;$i<=$x;$i++){
$result *= $i;
}
}
return $result;
}
$n = number_format($n,0,'.','');
$a = str_split($n);
echo array_sum($a);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment