(12C) Luhn algorithm
|
04-24-2018, 08:00 AM
(This post was last modified: 04-24-2018 01:13 PM by pinkman.)
Post: #3
|
|||
|
|||
RE: (12C) Luhn algorithm
Thanks Dieter!!
I'm ashamed I forgot to use LastX, and I'm really impressed with your optimizations. The 9 comparison with a combination of both x<=y and x=0 is a good sample of knowledge sharing. I did not want to use a toggle to identify the odd/even case, because of the advantage of having a counter of digits processed. I found a new solution based on the deterministic result of dividing by 2 any integer: 0 or 0.5. Thus multiplying by 2 and adding 1 gives a factor suitable for any digit to process, without using a test. The code might be a bit slower, but shorter and easy to read and maintain (no gto). Same usage: clear R0 and R1, enter the first (max 10) lower digits, then r/s for each digit including leading zeros, then enter the next digits, r/s again... Result in R0, number of processed digits in R1. If R0 is 10*N then Luhn is OK. Code:
|
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(12C) Luhn algorithm - pinkman - 04-18-2018, 06:29 PM
RE: (12C) Luhn algorithm - Dieter - 04-23-2018, 08:19 AM
RE: (12C) Luhn algorithm - pinkman - 04-24-2018 08:00 AM
RE: (12C) Luhn algorithm - Dieter - 04-24-2018, 06:35 PM
RE: (12C) Luhn algorithm - Dieter - 04-24-2018, 07:40 PM
RE: (12C) Luhn algorithm - pinkman - 04-24-2018, 08:27 PM
RE: (12C) Luhn algorithm - Dieter - 04-25-2018, 07:22 AM
RE: (12C) Luhn algorithm - pinkman - 04-25-2018, 02:52 PM
|
User(s) browsing this thread: 1 Guest(s)