Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Numbers Factory by J.W
# second version after reading the solution from makoto_yamagata:
# https://py.checkio.org/mission/number-factory/publications/makoto_yamagata/python-3/first/?ordering=most_voted&filtering=all
def checkio(n):
for i in range(9, 1, -1):
if n % i == 0:
b = int(n/i) if n/i <= 9 else checkio(int(n/i))
if b:
return int(str(b)+str(i)) # i is the bigger digit. put it at the end.
return 0
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"
March 29, 2018