|
|
from funcs import *from termcolor import coloredops = ( '+', '-', '*', '/', )
par = ( '{n[0]}{o[0]}{n[1]}{o[1]}{n[2]}{o[2]}{n[3]}', '({n[0]}{o[0]}{n[1]}){o[1]}({n[2]}{o[2]}{n[3]})', '({n[0]}{o[0]}{n[1]}{o[1]}{n[2]}){o[2]}{n[3]}', '({n[0]}{o[0]}{n[1]}){o[1]}{n[2]}{o[2]}{n[3]}', )colors = [ 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan' ]var = ('a','b','c','d')ps = perms(4)
def find(numbs,fast = False):
answers = [[],[]]
t = True
for perm in ps: perm = list( map( lambda x:x-1,perm ) ) org = perm perm = choose(numbs,perm)
for o in range(4**3): o = zp(con_base(o,4),3) o = choose(ops,o)
for p in par: g = p.format(**{'n':perm,'o':o}) try: if round(eval(g),2) == 10: if fast: return [g] else: var_subbed = choose(var,org) org = p.format(**{ 'n':var_subbed, 'o':o }) d = simplify(org) if not (d in answers[0]): answers[0].append(d) answers[1].append(g) except: pass return tuple(set(answers[1]))
Strng0 = 'Fancy colors? (y or n):'Strng1 = 'One or all solutions (one or all):'
fancy_colors = input(Strng0) == 'y'fast = input(Strng1) == 'all'print( find( list(range(1,5)),False ) )while True: if fancy_colors: random.shuffle(colors) for col in colors: for ans in find(getInput(input('Numbers:')),fast): print(colored(ans,col)) else: for ans in find(getInput(input('Numbers:')),fast): print(ans)
|