Post Reply 
(12C) Luhn algorithm
04-25-2018, 07:22 AM (This post was last modified: 04-25-2018 07:23 AM by Dieter.)
Post: #7
RE: (12C) Luhn algorithm
(04-24-2018 08:27 PM)pinkman Wrote:  There is another way to avoid the >9 test: add the 2 numbers, even if there is a leading zero.

It can also be done with the >9 test.
Here is a version that processes the complete number, so you don't have to press R/S several times:

Code:
01  1
02  0
03  ÷
04  INTG
05  LSTX
06  FRAC
07  1
08  0
09  x
10  RCL 1
11  2
12  ÷
13  FRAC
14  2
15  x
16  1
17  STO+1
18  +
19  x
20  9
21  X<>Y
22  X≤Y?
23  GTO 26
24  X<>Y
25  -
26  STO+0
27  R↓
28  R↓
29  X=0?
30  GTO  32
31  GTO 01
32  RCL 1
33  RCL 0
34  GTO 00

R1 is returned in Y and R0 in X. Simply check if the last digit is zero. Yes, with a few more steps the program could also do this.

The code up to line 28 works like the previous versions, so it's even one step shorter. And R2 is not required. ;-)

Dieter
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: 2 Guest(s)