"Factorials"
Given the first few factorials:
1! = 1
2! = 2 x 1 = 2
3! = 3 x 2 x 1 = 6
4! = 4 x 3 x 2 x 1 = 24
What is the sum of the first 15 factorials, NOT INCLUDING 0!?
Once you realise you are summing the factors it makes this challenge a lot more manageable.
Awnser:
1401602636313
Source:
function factorial($number) { if ($number < 2) { return 1; } else { return ($number * factorial($number-1)); } } function solution(){ $solution = 1; $factorial = 0; for($addfactorial = 1; $addfactorial <= 15; $addfactorial++){ $solution += factorial($addfactorial); } echo $solution - 1; }