Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
recursion solution in Clear category for Mathematically Lucky Tickets by domokdavid
def possible_values(data):
if len(data)==1: return {int(data)}
values_set = {int(data)}
for i in range(len(data)-1):
left_set = possible_values(data[:i+1])
right_set = possible_values(data[i+1:])
values_set.update({(x + y) for x in left_set for y in right_set})
values_set.update({(x - y) for x in left_set for y in right_set})
values_set.update({(x * y) for x in left_set for y in right_set})
values_set.update({(x / y) for x in left_set for y in right_set if y !=0})
return values_set
def checkio(data):
return 100 not in possible_values(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"
print("solved")
April 21, 2021