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.
Input
- the first and only line contains the credit card number (a string consisting of 16 digits)
Output
- to the standard output print "valid" if the given credit card number is valid or the total modulo 10 (from the step 4th) otherwise
You can solve this programming contest in Ruby, JavaScript, Python, PHP and more languages. If you want, you can also take part in other Challenges. Below you can find some of them:
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! :)