Post Reply 
(12C) Luhn algorithm
04-24-2018, 08:27 PM
Post: #6
RE: (12C) Luhn algorithm
(04-24-2018 06:35 PM)Dieter Wrote:  First of all: you can save two steps if you have the "1" in line 16 followed by a STO+1. This way the counter is incremented en passant and you can delete the three steps near the end that do it now.
Yes!!

(04-24-2018 06:35 PM)Dieter Wrote:  But... sometimes even good ideas don't work. All this would be fine, even with four steps saved, IF the 12C had an X<Y? test as originally shown in your listing (I now see you corrected this). But in fact the 12C features an X≤Y? test. This way the digit 9 will not get processed correctly. Since 9 ≤ 9 the test is true, so X=0? is also tested, which is false, so the CLX is not executed and the result is zero (9 – 9). So this method is not an option here.
Whoo, lack of test on my side!
There is another way to avoid the >9 test: add the 2 numbers, even if there is a leading zero.
This can be done with:

Code:

10
/
Intg
LastX
Frac
10
*
+

So I decided to store 10 in R2, to spare 2 lines.

New code is:

Code:

01 1
02 0
03 Sto 2
04 /
05 Intg
06 LastX
07 Frac
08 Rcl 2
09 *
10 Rcl 1
11 2
12 /
13 Frac
14 2
15 *
16 1
17 Sto+ 1
18 +
19 *
20 Rcl 2
21 /
22 Intg
23 LastX
24 Frac
25 Rcl 2
26 *
27 +
28 Sto+ 0
29 Rv
30 Gto 00

This time I think it has been tested!
Same usage, but now R2 is used.
Result in R0, counter in R1.
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)