Various incomplete solutions
This commit is contained in:
13
ProjectEuler/034/desc.yml
Normal file
13
ProjectEuler/034/desc.yml
Normal file
@ -0,0 +1,13 @@
|
||||
title: Find the sum of all numbers which are equal to the sum of the factorial of their digits.
|
||||
url: http://projecteuler.net/problem=34
|
||||
|
||||
desc: |
|
||||
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
|
||||
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
|
||||
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
|
||||
solution: Bruteforce
|
||||
solutons:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
|
16
ProjectEuler/034/solve.php
Normal file
16
ProjectEuler/034/solve.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
$num = 3;
|
||||
$result =0;
|
||||
for($num = 3; $num < 99999; $num++) {
|
||||
$sum = 0;
|
||||
foreach(str_split($num) as $digit) {
|
||||
$sum += fact($digit);
|
||||
}
|
||||
if($sum == $num) { $result += $sum;}
|
||||
}
|
||||
echo $result;
|
||||
|
||||
function fact($int){
|
||||
static $facts = array(1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880);
|
||||
return $facts[$int];
|
||||
}
|
Reference in New Issue
Block a user