Retired
Big Factorial (retired)
402 of 1,977devonparsons
Description:
The factorial of a number, n!
, is defined for whole numbers as the product of all integers from 1
to n
.
For example, 5!
is 5 * 4 * 3 * 2 * 1 = 120
Most factorial implementations use a recursive function to determine the value of factorial(n)
. However, this blows up the stack for large values of n
- most systems cannot handle stack depths much greater than 2000 levels.
Write an implementation to calculate the factorial of arbitrarily large numbers, without recursion.
Rules
n < 0
should returnnil
/None
n = 0
should return1
n > 0
should returnn!
Note
Codewars limits the amount of data it will send back and forth, which may introduce a false ceiling for how high of a value of n
it will accept. All tests use values less than this limit.
Algorithms
Fundamentals
Similar Kata:
Stats:
Created | Feb 27, 2015 |
Warriors Trained | 3120 |
Total Skips | 253 |
Total Code Submissions | 7291 |
Total Times Completed | 1977 |
Ruby Completions | 402 |
Python Completions | 1418 |
Scala Completions | 189 |
Total Stars | 23 |
% of votes with a positive feedback rating | 89% of 354 |
Total "Very Satisfied" Votes | 288 |
Total "Somewhat Satisfied" Votes | 57 |
Total "Not Satisfied" Votes | 9 |
Total Rank Assessments | 105 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 1 kyu |
Lowest Assessed Rank | 8 kyu |