Learning about the Lhon’s Algorithm
Like many of my blogs start out, I recently learned this during my Python learning through Udemy.
Lhon’s Algorithm, one of many methods used to validate credit card information. More specifically it helps determine if a credit card number is valid. It was exciting both in better understanding algorithms but also because it was cool to see a basic way that this happens in our world of online shopping and how it could potentially used in future projects, personal or work related.
Now, today will talk about how the algorithm is broken down. With how much goes into the algorithm, it also gave me great practice on how to look at algorithms piece by piece. Like in my Flatiron School labs, take it one part at a time and once it works, on to the next.
With a standard 16 digit credit card number, there are 7 steps in finding if the number is valid or not.
- Break the numbers down to a list with and index.
- Gather the odd numbers and find the sum
- Gather the even numbers and find their doubles (example: 5 => 10, 2 =>4 etc.)
- For any with a double digit (10 and up) break that number down to single digits and find the sum (10 would break down to 1 + 0 = 1, 11 as 1 + 1 = 2 and so on)
- Now find the sum of evens
- Find the sum of the collection of odds and the collection of evens
- Divide by 10. If there is a remainder of 0 the card is valid.
It seems like a lot but also complicated with how much is needed to be done. Next post we will go into the simplified code and how to think it out to get through the algorithm.