You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/practice/luhn/.docs/instructions.md
+15-16Lines changed: 15 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,35 +2,31 @@
2
2
3
3
Given a number determine whether or not it is valid per the Luhn formula.
4
4
5
-
The [Luhn algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) is
6
-
a simple checksum formula used to validate a variety of identification
7
-
numbers, such as credit card numbers and Canadian Social Insurance
8
-
Numbers.
5
+
The [Luhn algorithm][luhn] is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers and Canadian Social Insurance Numbers.
9
6
10
7
The task is to check if a given string is valid.
11
8
12
-
Validating a Number
13
-
------
9
+
## Validating a Number
14
10
15
-
Strings of length 1 or less are not valid. Spaces are allowed in the input,
16
-
but they should be stripped before checking. All other non-digit characters
17
-
are disallowed.
11
+
Strings of length 1 or less are not valid.
12
+
Spaces are allowed in the input, but they should be stripped before checking.
13
+
All other non-digit characters are disallowed.
18
14
19
-
## Example 1: valid credit card number
15
+
###Example 1: valid credit card number
20
16
21
17
```text
22
18
4539 3195 0343 6467
23
19
```
24
20
25
-
The first step of the Luhn algorithm is to double every second digit,
26
-
starting from the right. We will be doubling
21
+
The first step of the Luhn algorithm is to double every second digit, starting from the right.
22
+
We will be doubling
27
23
28
24
```text
29
25
4_3_ 3_9_ 0_4_ 6_6_
30
26
```
31
27
32
-
If doubling the number results in a number greater than 9 then subtract 9
33
-
from the product. The results of our doubling:
28
+
If doubling the number results in a number greater than 9 then subtract 9 from the product.
29
+
The results of our doubling:
34
30
35
31
```text
36
32
8569 6195 0383 3437
@@ -42,9 +38,10 @@ Then sum all of the digits:
42
38
8+5+6+9+6+1+9+5+0+3+8+3+3+4+3+7 = 80
43
39
```
44
40
45
-
If the sum is evenly divisible by 10, then the number is valid. This number is valid!
41
+
If the sum is evenly divisible by 10, then the number is valid.
42
+
This number is valid!
46
43
47
-
## Example 2: invalid credit card number
44
+
###Example 2: invalid credit card number
48
45
49
46
```text
50
47
8273 1232 7352 0569
@@ -63,3 +60,5 @@ Sum the digits
63
60
```
64
61
65
62
57 is not evenly divisible by 10, so this number is not valid.
0 commit comments