Update readme, create factorial_examples folder and move existing code into it

This commit is contained in:
froge 2025-07-31 17:29:09 +10:00
parent 4a346e5dd9
commit b786aa21a3
Signed by: froge
GPG key ID: A825E09930271BFA
4 changed files with 2 additions and 1 deletions

View file

@ -1,20 +0,0 @@
def factorial(n: int) -> int:
if n < 2:
return n
else:
return n * factorial(n-1)
def factorial_iter(n: int) -> int:
fact = 1
# Grab absolute value to ensure n is a positive integer
n = abs(n)
for i in range(2, n+1):
fact *= i
return fact
user_input = int(input("Insert number to calculate factorial for: "))
# Avoid recursion limit
if user_input < 1000:
print(f"Recursive factorial {user_input}: {factorial(user_input)}")
print(f"Iterative factorial {user_input}: {factorial_iter(user_input)}")