← Back to challenges

Recursion: Exact Factorial Bounds

PythonHardrecursionnumbersmath

Instructions

Create a recursive function that tests if a number is the exact upper bound of the factorial of n. If so, return a list that contains the exact factorial bound and n, or otherwise, the string "Not exact!".

Examples

is_exact(6) ➞ [6, 3]

is_exact(24) ➞ [24, 4]

is_exact(125) ➞ "Not exact!"

is_exact(720) ➞ [720, 6]

is_exact(1024) ➞ "Not exact!"

is_exact(40320) ➞ [40320, 8]

Notes

  • It is expected from the challenge-takers to come up with a solution using the concept of recursion or the so-called recursive approach.
  • There will be no exceptions to handle. All inputs are positive integers.
  • A non-recursive version of this challenge (of lesser difficulty and which gives you the total liberty of not using the recursive approach) can be found in here.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.