Post Reply 
(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:

01 1
02 0
03 /
04 Intg
05 LastX
06 Frac
07 1
08 0
09 *
10 Rcl 1
11 2
12 /
13 Frac
14 2
15 *
16 1
17 +
18 *
19 9
20 x<=y?
21 x=0?
22 CLX
23 -
24 Sto+ 0
25 Rv
26 1
27 Sto+ 1
28 Rv
29 Rtn
Find all posts by this user
Quote this message in a reply
Post Reply 


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)