Various incomplete solutions

This commit is contained in:
FuryFire
2011-04-10 13:19:21 +02:00
parent 94dc7ec373
commit 53e3cf4358
15 changed files with 173 additions and 8 deletions

13
ProjectEuler/034/desc.yml Normal file
View 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

View 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];
}