【每日一题20220620】最佳算式

:mage:‍ 给定3个数字a,b,c,我们的任务是使用+,*()将它们组成数学算式。请编写一个函数,找出最终得数最大的那个算式。

【示例】
输入:1,2,3
输出:9
解释:根据数字1,2,3,可以组成1 * (2 + 3) = 5,或者1 * 2 * 3 = 6,或者1 + 2 * 3 = 7,以及(1 + 2) * 3 = 9,所以其中最大得数是9。

题目难度:简单
题目来源:codewars-Expressions Matter

def solution(a:int, b:int, c:int)-> int:
    # your code here

assert solution(1,2,3) == 9
assert solution(2,1,2) == 6
assert solution(3,5,7) == 105
def solution(a: int, b: int, c: int) -> int:
    return max([a * (b + c), a * b * c, a + b * c, (a + b) * c])
def solution(a: int, b: int, c: int) -> int:
	# your code here
	return max([a * (b + c), a * b * c, a + b * c, (a + b) * c, a + b + c])

assert solution(1, 2, 3) == 9
assert solution(1, 1, 1) == 3
assert solution(2, 1, 2) == 6
assert solution(3, 5, 7) == 105
def solution(a:int, b:int, c:int)-> int:

    return max([a * (b + c), (a + b) * c, a * b * c, a * b + c, a + b * c, a + b + c])


if __name__ == '__main__':
    assert solution(1,2,3) == 9
    assert solution(2,1,2) == 6
    assert solution(3,5,7) == 105
def solution(a:int, b:int, c:int)-> int:
    return max([a*(b+c),a*b*c,a+b*c,(a+b)*c])
def solution(a:int, b:int, c:int)-> int:
    return max([a*b*c,(a+b)*c,a*(b+c),a+b*c,a*b+c,a+b+c])

assert solution(1,2,3) == 9
assert solution(2,1,2) == 6
assert solution(3,5,7) == 105
def solution(a:int, b:int, c:int)-> int:
    # your code here
    return max([(a + b + c), a * (b + c), (a + b) * c, (a + c) * b, (a * b * c)])


assert solution(1,2,3) == 9
assert solution(2,1,2) == 6
assert solution(3,5,7) == 105
def expression_matter(a, b, c):
    if 1 not in {a,b,c}:
        return a*b*c
    return max(a * (b + c),(a + b) * c,a + b + c)
def solution(a:int, b:int, c:int)-> int:
    int_list=sorted([a,b,c],reverse=False)
    if 1 in int_list:
        return (int_list[0]+int_list[1])*int_list[2]
    else:
        return int_list[0]*int_list[1]*int_list[2]

assert solution(1,2,3) == 9
assert solution(2,1,2) == 6
assert solution(3,5,7) == 105