def first_power(heros, nb_of_switches):
for _ in range(nb_of_switches):
min_ = min(heros)
pos = heros.index(min_)
heros[pos] = 0-min_
s = 0
for hero in heros:
s = s + hero
print('Possibly flipping the power of the same hero many times, the greatest achievable power is %d.' % (s))
def second_power(heros, nb_of_switches):
switchded_heros = list()
for _ in range(nb_of_switches):
min_ = min(heros)
switchded_heros.append(0-min_)
heros.remove(min_)
s = 0
for hero in heros:
s = s+hero
for hero in switchded_heros:
s = s+hero
print('Flipping the power of the same hero at most once, the greatest achievable power is %d. ' % (s))
def third_power(heros, nb_of_switches,powerlist,isprint):
for i in range(len(heros)-nb_of_switches+1):
current = 0
s = 0
for pos in range(len(heros)):
if (i+current == pos) and (current < nb_of_switches):
s = s+(0-heros[pos])
current += 1
else:
s = s+heros[pos]
powerlist.append(s)
max_ = max(powerlist)
if isprint:
print('Flipping the power of nb_of_flips many consecutive heroes, the greatest achievable power is %d. '%(max_))
def fourth_power(heros):
powerlist = list()
for i in range(len(heros)+1):
third_power(heros,i,powerlist,False)
max_ = max(powerlist)
print('Flipping the power of arbitrarily many consecutive heroes, the greatest achievable power is %d. '%(max_))