Retired

Luhn Algorithm (retired)

Description:

Challenge: Validating Credit Card Numbers

Credit card numbers can be validated with a process called the Luhn algorithm. Simply stated, the Luhn algorithm works like this:

  1. Starting with the next to last digit and continuing with every other digit going back to the beginning of the card, double the digit.
  2. Sum all untouched digits with the digits of the doubled numbers in the number.
  3. If that total is a multiple of 10, the number is valid.

For example, given the card number 4408 0412 3456 7893: ``` Orig : 4 4 0 8 0 4 1 2 3 4 5 6 7 8 9 3 Step 1: 8 4 0 8 0 4 2 2 6 4 10 6 14 8 18 3 Step 2: 8+4+0+8+0+4+2+2+6+4+1+0+6+1+4+8+1+8+3 = 70 Step 3: 70 % 10 == 0 ```

To Do

Define a function luhn that takes a card number card and returns true if the card number is valid or false if it is not valid.

For your reference:

  • 1234567890123456 is not valid
  • 4408041234567893 is valid
  • 38520000023237 is valid
  • 4222222222222 is valid
Algorithms
Logic
Fundamentals

Stats:

CreatedJun 29, 2017
Warriors Trained76
Total Skips0
Total Code Submissions49
Total Times Completed15
JavaScript Completions15
Total Stars2
% of votes with a positive feedback rating21% of 7
Total "Very Satisfied" Votes1
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes5
Total Rank Assessments12
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • AWhitleyGA Avatar
Ad