Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Mathematically Lucky Tickets by arbores401
from operator import add, sub, mul, truediv
operators = add, sub, mul, truediv
def results(s):
yield int(s)
yield from (op(a, b)
for i in range(1, len(s))
for a in results(s[:i])
for b in results(s[i:])
for op in operators
if b != 0 or op != truediv)
def checkio(data):
return all(x != 100 for x in results(data))
# These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio('000000') == True, "All zeros"
assert checkio('707409') == True, "You can not transform it to 100"
assert checkio('595347') == False, "(5 + ((9 / (3 / 34)) - 7)) = 100"
assert checkio('271353') == False, "(2 - (7 * (((1 / 3) - 5) * 3))) = 100"
April 13, 2020