#K88427. Luhn's Algorithm Validator
Luhn's Algorithm Validator
Luhn's Algorithm Validator
Given a credit card number as a string of digits, determine whether it is valid according to Luhn's algorithm. The algorithm works as follows:
- Starting from the rightmost digit and moving left, double the value of every second digit.
- If the result of this doubling is greater than 9, subtract 9 from it.
- Sum all the digits (both those that were doubled and those that were not).
- The credit card number is valid if and only if the total sum is a multiple of 10, i.e., \(total\_sum \mod 10 = 0\).
Your task is to implement this check. Read the credit card number from standard input and output True
if the number is valid, or False
otherwise.
inputFormat
The input consists of a single line containing a string of digits that represents the credit card number. There will be no spaces or other characters.
outputFormat
Output a single line: True
if the credit card number is valid according to Luhn's algorithm; otherwise, output False
.
4532015112830366
True