Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
O(log number) solution in Clear category for Numbers Factory by ottosmo
from functools import reduce
def checkio(number):
n = number
digit_factors = []
f = 9
while n > 1 and f > 1:
if n % f == 0:
digit_factors.append(f)
n = n // f
else:
f = f-1
return 0 if n>1 else reduce((lambda x, y: x*10 + y), list(reversed(digit_factors)))
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"
print("success")
Nov. 19, 2016
Comments: