Implement a credit-card validation suite using the Luhn algorithm and brand patterns.
Brand patterns:
-
VISA: 16 digits, starts with 4
-
MASTERCARD: 16 digits, starts with 51–55
-
AMEX: 15 digits, starts with 34 or 37
Tasks:
-
Given a card number, output whether it's valid and which brand it belongs to. Possible outputs: ["INVALID_CHECKSUM", "VISA", "MASTERCARD", "AMEX"].
-
Extend
(
1): if the checksum is valid but the number doesn't match any known brand pattern, output "UNKNOWN".
-
Inputs may contain asterisk (*) wildcards, e.g., "****424242424242". Return the number of possible valid cards per brand. Example output format: ["VISA,1", "MASTERCARD,10"]. Notes: A card may match multiple brands; if the brand is already known, the count of valid cards equals 10^(number_of_asterisks -
1).
-
Error-correction: the input ends with a question mark "?" indicating the observed number may have exactly one error among: changed digit, removed digit, added digit, or swapped adjacent digits (e.g., "4333220284765319?"). Output all possible original valid card numbers that would pass Luhn and match a brand pattern.