-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressions Matter.py
More file actions
29 lines (26 loc) · 1.12 KB
/
Expressions Matter.py
File metadata and controls
29 lines (26 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Given three integers a, b, and c, return the largest number obtained after inserting the operators +, *, and parentheses (). In other words, try every combination of a, b, and c with the operators, without reordering the operands, and return the maximum value.
# Example
# With the numbers 1, 2, and 3, here are some possible expressions:
# 1 * (2 + 3) = 5
# 1 * 2 * 3 = 6
# 1 + 2 * 3 = 7
# (1 + 2) * 3 = 9
# The maximum value that can be obtained is 9.
# Notes
# The numbers are always positive, in the range 1 ≤ a, b, c ≤ 10.
# You can use the same operation more than once.
# It is not necessary to use all the operators or parentheses.
# You cannot swap the operands. For example, with the given numbers, you cannot get the expression (1 + 3) * 2 = 8.
# Input and Output Examples
# expressionsMatter(1, 2, 3) ==> 9, because (1 + 2) * 3 = 9.
# expressionsMatter(1, 1, 1) ==> 3, because 1 + 1 + 1 = 3.
# expressionsMatter(9, 1, 1) ==> 18, because 9 * (1 + 1) = 18.
def expression_matter(a, b, c):
return max(
a + b + c,
a * b * c,
a * (b + c),
a + b * c,
a * b + c,
(a + b) * c
)