Skip to content

Instantly share code, notes, and snippets.

@WorryingWonton WorryingWonton/sum13.py Secret
Last active Apr 8, 2019

Embed
What would you like to do?
sum13 solution which addresses missing test case.
#Problem URL: https://codingbat.com/prob/p167025
def sum13(nums):
for idx in range(len(nums) - 1):
if nums[idx] == 13:
nums[idx] = 0
nums[idx + 1] = (0 if nums[idx + 1] != 13 else 13)
return sum(nums) - ((13 if nums[-1] == 13 else 0) if nums else 0)
assert sum13([]) == 0
assert sum13([13]) == 0
assert sum13([1]) == 1
assert sum13([1, 13]) == 1
assert sum13([13, 1]) == 0
# Simplest form of missing case
assert sum13([13, 13, 1]) == 0
assert sum13([2, 13, 13, 1]) == 2
assert sum13([1, 2, 3]) == 6
assert sum13([1, 2, 13, 1, 13, 13, 7, 9]) == 12
assert sum13([13, 1, 2, 13, 1, 13, 13, 7, 9]) == 11
assert sum13([13, 1, 2, 13, 1, 13, 13, 13, 7, 9]) == 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.