Validate Credit Card Number Medium

+100 PTS

Before you start the test, check out our tutorial challenge

  • TYPE CODE PRACTICE CHALLENGE
  • LANGUAGES BASH, C, C++, C# AND 21 MORE
    LANGUAGES BASH, C, C++, C#, CLOJURE, ELIXIR, ERLANG, GO, GROOVY, HASKELL, JAVA, JAVASCRIPT, JULIA, KOTLIN, NIM, PERL, PHP, PYTHON2, PYTHON, RUBY, RUST, SCALA, SWIFT, TYPESCRIPT, VB
  • TIME ~25MIN

Validate Credit Card Number

Challenge outline

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:

  1. 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.
  2. If the result of this doubling operation is greater than 9, then add the digits of the result.
  3. Take the sum of all the digits.
  4. 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 June 2019 competitions. 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! :)