Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Concise algorithm solution in Speedy category for Mathematically Lucky Tickets by Igor_Sekretarev
from itertools import product
def possible_results(s: str) -> int:
yield int(s)
for i in range(1, len(s)):
for x,y in product(possible_results(s[:i]), possible_results(s[i:])):
yield from (x+y, x-y, x*y)
if y:
yield x/y
def checkio(data: str) -> bool:
return all(result!=100 for result in possible_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 25, 2021
Comments: