-
-
Save WorryingWonton/777fa30f854d23cae198af12cacd3ea9 to your computer and use it in GitHub Desktop.
sum13 solution which addresses missing test case.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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