Luhn Algorithm: Credit Card Checker

Luhn Algorithm: Credit Card Checker

Use Luhn algorithm to validate credit card numbers. Every credit card number is given as a string and has a correct form of four four-digit blocks, separated by single whitespace.

For this particular purpose, the algorithm includes such steps:

  1. Double every second digits starting from the rightmost.

  2. If the result of doubling is greater than 9, add the digits of the number.

  3. Sum all digits.

  4. Check if the sum is clearly divisible by 10.

example

Input: String (str).

Output: Boolean value (bool).

Examples:

assert checker("4137 8947 1175 5904") == True
assert checker("5468 1234 5678 9123") == False
assert checker("4539 1488 0343 6467") == True