+ 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
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
+ 19
https://code.sololearn.com/cJa3D2E7O4p7/?ref=app
+ 12
https://code.sololearn.com/cL29Mw48q51w/?ref=app
+ 7
+ 5
Even better : finds a specific target, works for any length, and set of operations including brackets https://code.sololearn.com/cTSlP5186dmM/?ref=app
+ 4
Clean but lazy solution..đ
đđ
https://code.sololearn.com/cAYq0sr6N8Lj/?ref=app
+ 2
Shorter version
https://code.sololearn.com/cPsbrOHTCCgD/?ref=app
+ 2
Using a little trick:
https://code.sololearn.com/c77WvMcGeRZZ/?ref=app
+ 2
My solution:
https://code.sololearn.com/ciG77Rr3d5f6/?ref=app
+ 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))