Post Reply 
(12C) Luhn algorithm
04-24-2018, 07:40 PM (This post was last modified: 04-24-2018 08:20 PM by Dieter.)
Post: #5
RE: (12C) Luhn algorithm
(04-18-2018 06:29 PM)pinkman Wrote:  referring to the wikipedia page of the Luhn algorithm, I propose an implementation for the 12c.

Here is a version for a special application of the Luhn algorithm. The latter is often used to add a check digit to a locomotive's class/serial number. The German Federal Railways have been using this method since 50 years now, which maybe is a good reason to introduce this special program version. ;-)

Code:
01  STO 0
02  0
03  STO 1
04  STO 2
05  R↓
06  X=0?
07  GTO 33
08  1
09  0
10  ÷
11  INT
12  LSTX
13  FRAC
14  1
15  0
16  x
17  2
18  RCL 1
19  -
20  STO 1
21  X=0?
22  GTO 30
23  x
24  9
25  X≤Y?
26  X=0?
27  CLX
28  -
29  ENTER
30  R↓
31  STO+2
32  GTO 05
33  RCL 2
34  ,
35  9
36  x
37  FRAC
38  STO+0
39  RCL 0
40  FIX 1
41  GTO 00
Edit: added a missing line

Usage:
Enter the six-digit vehicle number (class and serial number) and the program adds the check digit (right of the decimal point).

Example:
103 118 => 103.118,6
111 111 => 111.111,1

You can also use this program to calculate the check digit for other numbers with up to nine digits:
123456789 => 123.456.789,7

If you replace line 38...40 with "10 x" only the check digit is returned and up to 10 digits can be processed.
In this case you may also replace the initial STO 0 with FIX 0. ;-)

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