Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Numbers Factory by Mateusz_Tomkowiak
def checkio(number):
numbers = []
i = 2
while (number > 1):
if (number % i == 0):
numbers.append(i)
number /= i
i = 2
elif (i >= 10):
return False
else:
i += 1
while(True):
# check 9
if (numbers.count(3) >= 2):
a = numbers.pop(numbers.index(3))
b = numbers.pop(numbers.index(3))
# check 8
elif(numbers.count(2)>=3):
a = numbers.pop(numbers.index(2))
b = numbers.pop(numbers.index(2))*numbers.pop(numbers.index(2))
# check 8
elif(numbers.count(2)>=1 and numbers.count(4)>=1):
a = numbers.pop(numbers.index(2))
b = numbers.pop(numbers.index(4))
# check 6
elif (numbers.count(2) >= 1 and numbers.count(3) >= 1):
a = numbers.pop(numbers.index(2))
b = numbers.pop(numbers.index(3))
#check 4
elif (numbers.count(2) >= 2):
a = numbers.pop(numbers.index(2))
b = numbers.pop(numbers.index(2))
else:
break
numbers.append(a*b)
numbers.sort()
return int(''.join(map(str, numbers)))
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"
Oct. 21, 2016