yessah
BAN USERin Python, though I think there is a bug when the first number is a negative.
def get_arithmetics(v1, v2):
return [
v1 * v2,
v1 + v2,
v1 - v2,
v1 % v2,
]
def get_max(input):
totals = [1, input[0]]
for index, num in enumerate(input[1:]):
index = index+1
rhs = max(get_arithmetics(input[index-1], num))
max_potentials = [max(get_arithmetics(totals[index], num))]
max_potentials.append(totals[index-1] * rhs)
if (len(totals)>2):
max_potentials += get_arithmetics(totals[index-1], rhs)
totals.append(max(max_potentials))
return totals[-1]
assert get_max([3, 4, 5, 1]) == 72, "[3, 4, 5, 1] == 72"
assert get_max([1, 1, 1, 5]) == 15, "[1, 1, 1, 5] == 15"
assert get_max([8, 5, -1]) == 48, "8, 5, -1] == 48"
- yessah March 01, 2019