Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
lru_cache and operator => function can be written in 2 functions of one line solution in Uncategorized category for Mathematically Lucky Tickets by Ylliw
from operator import add,sub,mul,truediv
from functools import lru_cache
@lru_cache(maxsize=None)
def compute (data):
return set([int(data)]) \
|set([op(a,b)
for i in range(0,len(data)-1)
for a in compute(data[:i+1])
for b in compute(data[i+1:])
for op in (add,sub,mul,truediv)
if (op,b) != (truediv,0)])
def checkio(data):
return 100 not in compute(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"
July 11, 2019
Comments: