Skip to content

Instantly share code, notes, and snippets.

@WorryingWonton
Last active April 8, 2019 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WorryingWonton/777fa30f854d23cae198af12cacd3ea9 to your computer and use it in GitHub Desktop.
Save WorryingWonton/777fa30f854d23cae198af12cacd3ea9 to your computer and use it in GitHub Desktop.
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