Implement utilities for credit-card validation and inference using the Luhn algorithm. Card brands and formats: VISA — 16 digits, starts with 4; MASTERCARD — 16 digits, starts with 51, 52, 53, 54, or 55; AMEX — 15 digits, starts with 34 or 37. Tasks:
-
Given a digit-only card number, return whether the checksum is valid and which brand it belongs to. Possible outputs: ["INVALID_CHECKSUM", "VISA", "MASTERCARD", "AMEX"].
-
Extend
(
-
to also return "UNKNOWN" if the checksum is valid but the number does not match any known brand pattern.
-
Now allow '*' characters representing unknown digits (e.g., "****424242424242"). Return the number of possible valid cards per brand. Output as a list of "BRAND,count" pairs; multiple brands may be possible for the same pattern.
-
Given an observed string like "4333220284765319?", where the trailing '?' indicates that exactly one error occurred to the preceding digits, and the error is one of: changed digit, removed digit, added digit, or swapped two digits (transposition), output all possible original valid card numbers (and their brands) that could have produced the observed string.