Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Numbers Factory by cinekk
def is_prime(number):
for i in range(2, (number//2)+1):
if number % i == 0: return False
return True
def checkio(number):
if is_prime(number):
return 0
result = ''
factorials = []
while number > 9:
found = False
for i in range(9,1,-1):
if number % i == 0:
factorials.append(i)
found = True
number //= i
break
if found is False:
return 0
factorials.append(number)
for el in sorted(factorials):
result += str(el)
return int(result)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(20) == 45, "1st example"
assert checkio(21) == 37, "2nd example"
assert checkio(17) == 0, "3rd example"
assert checkio(33) == 0, "4th example"
assert checkio(3125) == 55555, "5th example"
assert checkio(9973) == 0, "6th example"
Nov. 28, 2016