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 return nil/ None
  • n = 0 should return 1
  • n > 0 should return n!

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

Stats:

CreatedFeb 27, 2015
Warriors Trained3120
Total Skips253
Total Code Submissions7291
Total Times Completed1977
Ruby Completions402
Python Completions1418
Scala Completions189
Total Stars23
% of votes with a positive feedback rating89% of 354
Total "Very Satisfied" Votes288
Total "Somewhat Satisfied" Votes57
Total "Not Satisfied" Votes9
Total Rank Assessments105
Average Assessed Rank
6 kyu
Highest Assessed Rank
1 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • devonparsons Avatar
  • jhoffner Avatar
  • nhomble Avatar
  • anter69 Avatar
  • fredc Avatar
  • hobovsky Avatar
  • akar-0 Avatar
Ad