def testall(n,k,pool): t = np.array([1]*( (n/(k+1)) *k) + [-k]*(n/(k+1))) next_permutation(t) perms = gen_perm(t) if pool: rr = pool.imap(_t, ( (n,k,i) for i in perms), 100) return (i for i in rr if i != True) else: return (i for i in (runtest('./usu',n,k,test) for test in perms) if i!=True)
def permutations(A): result = [] while True: result.append(A.copy()) A = next_permutation(A) if not A: break return result
def gen_perm(x): i=0 while True: yield x.copy() # next_permutation modyfikuje in-place i+=1 if not next_permutation(x): #print i, "permutations" break
def slowOptimalPairing(x,y): n,d = x.shape assert y.shape==(n,d) bestDist = np.inf bestP = None for p in next_permutation.next_permutation(range(n)): dist = sumOfDistances(x[p],y) if dist<bestDist: bestDist = dist bestP = p return bestP
arr = [int(x) for x in input().split()] arr.sort() #loop symbols eg[0,0,1] where [0,1,2,3]represents[+,-,*,/] n = len(arr) symbols = [[j,k,l] for j in range(4) for k in range(4) for l in range(4)] solutions = [] while True: for symbol in symbols: parenthesisCom = [0,1,2] while True: result = Points24(arr, symbol, parenthesisCom) if result != 'Divisor 0': if abs(result-target) < 1e-8: solution = Expression(arr,symbol,parenthesisCom) solutions.append(solution) if not next_permutation.next_permutation(parenthesisCom): break if not next_permutation.next_permutation(arr): break for i, solution in enumerate(solutions): print("#{}: {} = 24".format(i + 1, solution)) # current = [2,1, 3, 4] # symbol = [0,1,3] # parenthesisCom = [1,2,0] # print(current,symbol,parenthesisCom) # print(Points24(current,symbol,parenthesisCom)) # print(Expression(current,symbol,parenthesisCom))