+ 23

[ ASSIGNMENT: ] Expressions Matter

TASK : Given three integers a, b, c, return the largest number obtained after inserting the following operators and brackets  +,  *,  ( ) For Example : : 1. expressionsMatter(1,2,3) --> return 9 After placing signs and brackets, the Maximum value obtained from the expression is (1+2) * 3 = 9 2. expressionsMatter(9,1,1) --> return 18 After placing signs and brackets, the Maximum value obtained from the expression is 9 * (1+1) = 18 HappyCodings!:-) https://code.sololearn.com/WK4SG3ldwZuv/?ref=a

19th May 2018, 8:16 AM
Danijel Ivanović
Danijel Ivanović - avatar
14 Answers
+ 22
Consider an Example : With the numbers are 1, 2 and 3, here are some ways of placing signs and brackets 1 * (2+3) = 5 1 * 2 * 3 = 6 1 + 2 * 3 = 7 (1+2) * 3 = 9 the Maximum value,  that you can obtain is 9 NOTE : - The numbers are always positive. - The numbers are in the range  (1 ≀ a, b, c ≀ 10). - You can use the same operation more than once. - It's not necessary to place all the signs and brackets. - Repetition in numbers may occur. - You cannot swap the operands. For instance, in the given example you can't get expression (1+3) * 2 = 8
19th May 2018, 8:18 AM
Danijel Ivanović
Danijel Ivanović - avatar
19th May 2018, 9:14 AM
MeanMachine
MeanMachine - avatar
+ 19
https://code.sololearn.com/cJa3D2E7O4p7/?ref=app
19th May 2018, 1:54 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 12
https://code.sololearn.com/cL29Mw48q51w/?ref=app
19th May 2018, 2:36 PM
LukArToDo
LukArToDo - avatar
20th May 2018, 3:17 AM
Nevfy
+ 5
Even better : finds a specific target, works for any length, and set of operations including brackets https://code.sololearn.com/cTSlP5186dmM/?ref=app
19th May 2018, 1:26 PM
VcC
VcC - avatar
+ 4
Clean but lazy solution..😅😀😉 https://code.sololearn.com/cAYq0sr6N8Lj/?ref=app
19th May 2018, 6:29 PM
Zoetic_Zeel
Zoetic_Zeel - avatar
19th May 2018, 4:32 PM
VcC
VcC - avatar
20th May 2018, 1:16 PM
VĂ­ctor
VĂ­ctor - avatar
24th May 2018, 1:11 PM
lemmi
lemmi - avatar
+ 1
My code (Written by language python) def d2(x1,x2): if x1>1 and x2>1: return x1*x2 else: return x1+x2 def d3(x,y,z): return max(d2(x,d2(y,z)), d2(y,d2(x,z)), d2(z,d2(x,y)), x*y*z, x+y+z ) a,b,c=eval(input()),eval(input()),\ eval(input()) print(d3(a,b,c))
20th May 2018, 2:46 AM
You
You - avatar
19th May 2018, 11:13 PM
John Wells
John Wells - avatar