Hello and welcome to the challenge!
In this task your goal is to check if the given credit card number is valid. For this purpose you have to use the Luhn algorithm, which looks like this:
- From the rightmost digit, which is the check digit, and moving left, double the value of every second digit. The check digit is not doubled.
- If the result of this doubling operation is greater than 9, then add the digits of the result.
- Take the sum of all the digits.
- If the total modulo 10 is equal to 0 then the number is valid according to the Luhn formula, otherwise it is not valid.
- the first and only line contains the credit card number (a string consisting of 16 digits)
- to the standard output print "valid" if the given credit card number is valid or the total modulo 10 (from the step 4th) otherwise
Did you like this challenge and would like to try your hand at some interesting big programming competitions? Check what’s all over the news in tech world in June 2019 in our article with upcoming IT Conferences, Hackathons and Online Challenges in June 2019.
Have fun and good luck! :)