Skip to content

Instantly share code, notes, and snippets.

@sumoward
Created June 24, 2014 14:23
Show Gist options
  • Save sumoward/43717356cdad2adaacbe to your computer and use it in GitHub Desktop.
Save sumoward/43717356cdad2adaacbe to your computer and use it in GitHub Desktop.
def checkio(array):
"""
sums even-indexes elements and multiply at the last
"""
length = len(array)
if length == 0:
return 0
ans = 0
for x in range(length):
if x==0 or x%2 ==0:
ans = ans + array[x]
return ans * array[length -1]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([0, 1, 2, 3, 4, 5]) == 30, "(0+2+4)*5=30"
assert checkio([1, 3, 5]) == 30, "(1+5)*5=30"
assert checkio([6]) == 36, "(6)*6=36"
assert checkio([]) == 0, "Empty"
@sumoward
Copy link
Author

checkio = lambda array: sum(array[::2]) * sum(array[-1:])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment