Skip to content

Commit

Permalink
docs(luhn-algorithm): clarify input handling and steps in the example
Browse files Browse the repository at this point in the history
  • Loading branch information
mikysett committed Sep 26, 2023
1 parent 7e74d77 commit 29fdd80
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions subjects/luhn_algorithm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
Create a function which checks if a number is valid per the Luhn formula.

The function will receive a string and return a boolean.
An empty string or a number with only one digit will be considered an invalid number.
Spaces are accepted in the script but have to be stripped during the calculation (in other words they won't affect the result).

**Invalid inputs:** An empty string or a number with only one digit are considered invalid.
**Handling spaces:** Spaces are accepted but have to be ignored during the calculation (in other words they won't affect the result).

The Luhn formula is used to check if a number is a valid credit card number and in some other scenarios where you need to check a number fast and without accessing a database.

Expand All @@ -23,7 +24,7 @@ So we will get:

- `4539 3195 0343 6467`
- `4_3_ 3_9_ 0_4_ 6_6_`: numbers to modify
- `8_6_ 6_9_ 0_8_ 3_3_`: modified numbers
- `8_6_ 6_9_ 0_8_ 3_3_`: modified numbers (for numbers over 9 we subtracted 9 already)
- `8569 6195 0383 3437`: the new sequence of digits
- `80`: the sum of all digits
- `80` is evenly divisible by 10 so the result is `true`
Expand Down

0 comments on commit 29fdd80

Please sign in to comment.