A factorion is a number which equals the sum of the factorials of each of its digits.
For example: 145 is a factorion, because:
1! + 4! + 5! = 1 + 24 + 120 = 145
The following Python code will determine if a given number is a factorion.
import math
def isFactorion(n):
digits = getDigits(n)
digitSum = 0
for digit in digits:
digitSum += math.factorial(digit)
return n == digitSum
# Helper function.
# Get a list of digits as integers for a number n.
def getDigits(n):
return [int(digitChar) for digitChar in list(str(n))]
# Examples.
if isFactorion(145):
print("145 is a factorion")
else:
print("145 is not a factorion")
if isFactorion(185):
print("185 is a factorion")
else:
print("185 is not a factorion")
Output for the two examples:
145 is a factorion 185 is not a factorion
