Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Mathematically Lucky Tickets solution in Uncategorized category for Mathematically Lucky Tickets by capback250
# migrated from python 2.7
import itertools
def checkio(number):
mutations = [(1,1,1,1,1,1), (2,2,2), (3, 3)]
for x in set(itertools.permutations([1,1,1,1,2])):
mutations.append(x)
for x in set(itertools.permutations([1,1,2,2])):
mutations.append(x)
for x in set(itertools.permutations([1,1,1,3])):
mutations.append(x)
for x in set(itertools.permutations([1,2,3])):
mutations.append(x)
skobki = ["({} {} ({} {} ({} {} (({} {} {}) {} {}))))",
"({} {} (({} {} {}) {} ({} {} {})))",
"(({} {} {}) {} (({} {} ({} {} {})) {} {}))",
"({} {} ({} {} ({} {} ({} {} {}))))",
"({} {} (({} {} ({} {} {})) {} ({} {} {})))",
"(({} {} ({} {} {})) {} ({} {} {}))"]
sums = []
for mask in mutations:
# print mask
shablon = []
string = number[:]
c = 0
for i in mask:
shablon.append(string[c:c+i])
c += int(i)
# print shablon, len(shablon) - 1
for x in itertools.combinations_with_replacement(['+', '*', '-', '/'], len(shablon) - 1):
for z in set(itertools.permutations(x)):
expression = []
for id, val in enumerate([x +'.0' for x in shablon]):
expression.append(val)
if id < len(z):
expression.append(z[id])
# print expression
try:
for skonExpr in skobki:
if skonExpr.count('{}') == len(expression):
sums.append(eval(skonExpr.format(*expression)))
sums.append(eval(''.join(expression)))
except ZeroDivisionError:pass
return 100 not in sums
Feb. 14, 2016