Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Nice and easy solution in Clear category for CheckSum by coells
def checkio(data):
r = enumerate(ord(k) - 48 for k in data[::-1] if k.isalnum())
r2 = sum(j + (i & 1 ^ 1) * (j - 9 * (j // 5)) for i, j in r)
return [str(-r2 % 10), r2]
#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!")
April 14, 2014
Comments: