The Luhn algorithm catches typos in card and account numbers. From the rightmost digit, double every second digit (subtracting 9 if the result is over 9), sum everything, and the number is valid if the total is divisible by 10.
Implement:
luhn_valid(number): accepts a string that may contain spaces or hyphens; any other non-digit character, or fewer than 2 digits, makes it invalidluhn_check_digit(partial): the digit to append to a digit string to make it valid