def calculate(param): input = list(param) input.sort(reverse=True) # result = input[0] tempExpr = str(input[0]) maxExpr = tempExpr for i in range(1, 4): tempMax = "empty" for enclosed in [0, 1]: for pos in [0, 1]: for opr in ['+', '-', '*', '/']: tempExpr = maxExpr if (enclosed == 1): tempExpr = "(" + tempExpr + ")" if (pos == 0): tempExpr = tempExpr + opr tempExpr = tempExpr + str(input[i]) else: tempExpr = opr + tempExpr tempExpr = str(input[i]) + tempExpr tempScore = utils.countScore(tempExpr) if (tempMax == "empty"): tempMax = tempExpr if (tempScore >= utils.countScore(tempMax)): tempMax = tempExpr maxExpr = tempMax return [utils.countScore(maxExpr), maxExpr]
def calculate(param): input = list(param) input.sort(reverse=True) # result = input[0] tempExpr = str(input[0]) maxExpr = tempExpr for i in range(1, 4): tempMax = "empty" for opr in ['+', '-', '*', '/']: tempExpr = maxExpr tempExpr = tempExpr + opr tempExpr = tempExpr + str(input[i]) tempScore = utils.countScore(tempExpr) if (tempMax == "empty"): tempMax = tempExpr if (tempScore >= utils.countScore(tempMax)): tempMax = tempExpr maxExpr = tempMax return [utils.countScore(maxExpr), maxExpr]
def loop(self): x = (width * 0.001) y = (height * 0.001) cardX = 350 # x coordinate of card cardY = 200 # y coordinate of card screen.blit(self.jackImg, (x, y)) if self.cardHover: cardI = self.cardIBack2 else: cardI = self.cardIBack1 screen.blit(cardI, (cardX, cardY)) screen.blit(self.eks, (150, 550)) screen.blit(self.score, (100, 50)) screen.blit(self.poinI, (450, 50)) poin_s = utils.countScore(self.ekspresi) message_display(self.ekspresi, 400, 575) message_display(str(round(poin_s, 2)), 500, 70) message_display(str(round(self.poin, 2)), 150, 65) if (self.prog != -99): if (self.prog < 100): self.prog += 1 self.animateSys(self.prog)
def calculate(param): num = list(param) number_permut = list(itertools.permutations(num)) sign_permut = list(itertools.product([1,2,3,4],repeat=3)) # + - * / listskor = [] listexpr = [] for num in number_permut: for sign in sign_permut: for enclosing in [1,2,3,4,5]: if enclosing == 1: expr = "({:.0f}{}{:.0f}){}({:.0f}{}{:.0f})".format(num[0],getSymbol(sign[0]),num[1],getSymbol(sign[1]),num[2],getSymbol(sign[2]),num[3]) elif enclosing == 2: expr = "(({:.0f}{}{:.0f}){}{:.0f}){}{:.0f}".format(num[0],getSymbol(sign[0]),num[1],getSymbol(sign[1]),num[2],getSymbol(sign[2]),num[3]) elif enclosing == 3: expr = "{:.0f}{}(({:.0f}{}{:.0f}){}{:.0f})".format(num[0],getSymbol(sign[0]),num[1],getSymbol(sign[1]),num[2],getSymbol(sign[2]),num[3]) elif enclosing == 4: expr = "({:.0f}{}({:.0f}{}{:.0f})){}{:.0f}".format(num[0],getSymbol(sign[0]),num[1],getSymbol(sign[1]),num[2],getSymbol(sign[2]),num[3]) elif enclosing == 5: expr = "{:.0f}{}({:.0f}{}({:.0f}{}{:.0f}))".format(num[0],getSymbol(sign[0]),num[1],getSymbol(sign[1]),num[2],getSymbol(sign[2]),num[3]) listexpr.append(expr) listskor.append(utils.countScore(expr)) maxidx = 0 for i in range (len(listskor)): if (listskor[i]>listskor[maxidx]): maxidx = i return [listskor[maxidx],listexpr[maxidx]]
def calculate(param): inputNum = list(param) inputNum.sort(reverse=True) input = [] for num in inputNum: input.append(str(num)) pairs = [[8, 3, '*'], [6, 4, '*'], [12, 2, '*'], [25, 1, '-'], [24, 0, '+'], [23, 1, '+'], [26, 2, '-'], [27, 3, '-'], [22, 2, '+'], [21, 3, '+']] posiblePick = [[[1, 2], [3, 4]], [[1, 3], [2, 4]], [[1, 4], [2, 2]]] lowestDelta = 99 lowestConfLeft = "" lowestConfRight = "" lowestConfCenter = "" print(input) for pair in pairs: for pick in posiblePick: for swap in [True, False]: if (swap): pick.reverse() for internalSwap in [True, False]: if (internalSwap): pick[0].reverse() pick[1].reverse() for opr in ['+', '-', '*', '/']: for opr2 in ['+', '-', '*', '/']: deltaLeft = abs( eval(input[pick[0][0] - 1] + opr + input[pick[0][1] - 1]) - pair[0]) deltaRight = abs( eval(input[pick[1][0] - 1] + opr2 + input[pick[1][1] - 1]) - pair[1]) if ((deltaLeft + deltaRight) < lowestDelta): lowestConfLeft = "(" + input[ pick[0][0] - 1] + opr + input[pick[0][1] - 1] + ")" lowestConfRight = "(" + input[ pick[1][0] - 1] + opr2 + input[pick[1][1] - 1] + ")" lowestConfCenter = pair[2] lowestDelta = deltaLeft + deltaRight maxExpr = lowestConfLeft + lowestConfCenter + lowestConfRight return [utils.countScore(maxExpr), maxExpr]
def calculate(param): input = list(param) listoperations = [] #list kombinasi operasi listnumbers = input num = [] listnumbers.sort(reverse=True) #integer urutan angka for i in range(4): num.append(str(listnumbers[i])) i = 0 target = 24 cek = True while (i < 3): m = listnumbers[i] n = listnumbers[i + 1] if (target >= 0): if (m <= ((math.sqrt(target))) and n != 1): if (n != 1): listoperations.append('*') listnumbers[i + 1] = (m * n) else: listoperations.append('+') if (cek == True): target = target - m - n else: target = target - n cek = False else: listoperations.append('+') if (cek == True): target = target - m - n else: target = target - n cek = False else: listoperations.append('-') if (cek == True): target = target - m + n else: target = target + n cek = False i = i + 1 listoperations.append('') data = list(zip(num, listoperations)) for k in range(len(data)): data[k] = ''.join(data[k]) data = ''.join(data) return [utils.countScore(data), data]
def calculate(param): input = list(param) input.sort(reverse=True) tempExpr = [str(input[0])] maxExpr = tempExpr for i in range(1, 4): tempMax = [] for opr in ['+', '-', '*', '/']: index = 0 panjang = len(maxExpr) - 1 while (index <= panjang): tempExpr = maxExpr.copy() tempExpr.insert(index, opr) tempExpr.insert(index, str(input[i])) index = index + 2 tempScore = utils.countScore(toText(tempExpr)) if (tempMax == []): tempMax = tempExpr if (tempScore >= utils.countScore(toText(tempMax))): tempMax = tempExpr index = 1 panjang = len(maxExpr) while (index <= panjang): tempExpr = maxExpr.copy() tempExpr.insert(index, str(input[i])) tempExpr.insert(index, opr) index = index + 2 tempScore = utils.countScore(toText(tempExpr)) if (tempMax == []): tempMax = tempExpr if (tempScore >= utils.countScore(toText(tempMax))): tempMax = tempExpr maxExpr = tempMax.copy() if (i == 3): tempMax = maxExpr.copy() for enclosing in [1, 2, 3]: tempExpr = maxExpr.copy() if (enclosing == 1): tempExpr = ['(('] + tempExpr.copy() tempExpr.insert(4, ')') tempExpr.insert(7, ')') elif (enclosing == 2): tempExpr = ['('] + tempExpr.copy() tempExpr.insert(4, ')') tempExpr.insert(6, '(') tempExpr = tempExpr.copy() + [')'] elif (enclosing == 3): tempExpr.insert(2, '((') tempExpr.insert(6, ')') tempExpr = tempExpr.copy() + [')'] if (utils.countScore(toText(tempExpr)) >= utils.countScore( toText(tempMax))): tempMax = tempExpr.copy() maxExpr = tempMax.copy() return [utils.countScore(toText(maxExpr)), toText(maxExpr)]