Luhn's Algorithm - MATLAB Cody - MATLAB Central

Problem 45490. Luhn's Algorithm

Difficulty:Rate

Luhn's Algorithm is used as a checksum for credit card numbers or similar identifiers. It can detect single-digit changes and swapped digits. It consists of four steps:

  1. Double every second digit (starting with the last one).
  2. If a digit exceeds 9 due to the doubling, subtract 9.
  3. Add all the digits.
  4. Append the last digit of the sum to the original number.

More information can be found on https://en.wikipedia.org/wiki/Luhn_algorithm or in ISO/IEC 7812-1.

Your function takes the original numbers as a character vector, and it has to return a character vector that includes the checksum.

Solution Stats

42.86% Correct | 57.14% Incorrect
Last Solution submitted on Mar 01, 2024

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Problem Recent Solvers20

Suggested Problems

More from this Author1

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!