Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for CheckSum by aya.kanazawa
import re
def checkio(data):
def mpcl(number):
return sum(map(int, str(number * 2))) if number * 2 > 9 else number * 2
numbers = [ord(d) - 48 if d.isalpha() else int(d) for d in reversed(re.sub('[^A-Z\d]', '', data))]
sum_ = sum(mpcl(n) if i%2==0 else n for i, n in enumerate(numbers))
mod_ = sum_ % 10
return ["0", sum_] if mod_ == 0 else [str(10 - mod_), sum_]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert (checkio("799 273 9871") == ["3", 67]), "First Test"
assert (checkio("139-MT") == ["8", 52]), "Second Test"
assert (checkio("123") == ["0", 10]), "Test for zero"
assert (checkio("999_999") == ["6", 54]), "Third Test"
assert (checkio("+61 820 9231 55") == ["3", 37]), "Fourth Test"
assert (checkio("VQ/WEWF/NY/8U") == ["9", 201]), "Fifth Test"
print("OK, done!")
June 15, 2019