Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,53 @@
|
|||
string 0; \use zero-terminated strings
|
||||
|
||||
func Luhn(Str); \Return 'true' if digits in Str pass Luhn test
|
||||
char Str;
|
||||
int Len, Sum, I, Dig;
|
||||
[Len:= 0; \find length of Str
|
||||
while Str(Len) do Len:= Len+1;
|
||||
Sum:= 0; \sum even and odd digits
|
||||
for I:= 0 to Len-1 do \(no need to reverse)
|
||||
[if (I xor Len) & 1 then
|
||||
Sum:= Sum + Str(I) - ^0
|
||||
else [Dig:= Str(I) - ^0;
|
||||
Dig:= Dig*2;
|
||||
Sum:= Sum + Dig/10 + rem(0);
|
||||
];
|
||||
];
|
||||
return rem(Sum/10) = 0;
|
||||
]; \Luhn
|
||||
|
||||
func Valid(Str); \Return 'true' if valid ISIN code
|
||||
char Str, Str2(100);
|
||||
int Sum, I, J, C, V;
|
||||
[J:= 0;
|
||||
for I:= 0 to 12-1 do \convert letters in Str to digits in Str2
|
||||
[C:= Str(I);
|
||||
case of
|
||||
C>=^0 & C<=^9: [Str2(J):= C; J:= J+1];
|
||||
C>=^A & C<=^Z: [Str2(J):= (C-^A+10)/10 + ^0; J:= J+1;
|
||||
Str2(J):= rem(0) + ^0; J:= J+1]
|
||||
other return false;
|
||||
if I=1 & J#4 then return false; \first two chars not letters
|
||||
];
|
||||
if Str(I) # 0 then return false; \too long
|
||||
Str2(J):= 0; \terminate string
|
||||
return Luhn(Str2);
|
||||
]; \Valid
|
||||
|
||||
int ISIN, N;
|
||||
[ISIN:= ["US0378331005",
|
||||
"US0373831005",
|
||||
"U50378331005",
|
||||
"US03378331005",
|
||||
"AU0000XVGZA3",
|
||||
"AU0000VXGZA3",
|
||||
"FR0000988040"];
|
||||
for N:= 0 to 7-1 do
|
||||
[Text(0, ISIN(N));
|
||||
Text(0, if Valid(ISIN(N))
|
||||
then " is valid"
|
||||
else " is not valid");
|
||||
CrLf(0);
|
||||
];
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue