Cody

# Problem 45490. Luhn's Algorithm

Solution 2252146

Submitted on 3 May 2020 by Yuan
• Size: 21
• This is the leading solution.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
x = '0'; assert(isequal(luhn(x),'00'));

ans = 0 a = 1

2   Pass
x = '1'; assert(isequal(luhn(x),'12'));

ans = 2 a = 1

3   Pass
x = '5'; assert(isequal(luhn(x),'51'));

ans = 1 a = 1

4   Pass
x = '9'; assert(isequal(luhn(x),'99'));

ans = 9 a = 1

5   Pass
x = '10'; assert(isequal(luhn(x),'101'));

ans = 1 ans = 1 a = 1 2

6   Pass
x = '80'; assert(isequal(luhn(x),'808'));

ans = 8 ans = 8 a = 1 2

7   Pass
x = '080'; assert(isequal(luhn(x),'0808'));

ans = 0 ans = 8 ans = 8 a = 1 2 3

8   Pass
x = '180'; assert(isequal(luhn(x),'1800'));

ans = 2 ans = 0 ans = 0 a = 1 2 3

9   Pass
x = '1234567890'; assert(isequal(luhn(x),'12345678907'));

ans = 1 ans = 5 ans = 8 ans = 6 ans = 1 ans = 4 ans = 1 ans = 8 ans = 7 ans = 7 a = 1 2 3 4 5 6 7 8 9 10

### Community Treasure Hunt

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

Start Hunting!