CUSIP: Difference between revisions

1,046 bytes added ,  3 years ago
Added XPL0 example.
m (Replaced “cusip[0 ..< ^1]” by “cusip[0 .. ^2]”.)
(Added XPL0 example.)
Line 3,752:
68389X106 -> incorrect
68389X105 -> correct
</pre>
 
=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminated strings
 
func Valid(Cusip); \Return 'true' if valid CUSIP code
char Cusip;
int Sum, I, C, V;
[Sum:= 0;
for I:= 0 to 8-1 do
[C:= Cusip(I);
ChOut(0, C);
case of
C>=^0 & C<=^9: V:= C-^0;
C>=^A & C<=^Z: V:= C-^A+10;
C=^*: V:=36;
C=^@: V:=37;
C=^#: V:=38
other V:= -1;
if I&1 then V:= V*2;
Sum:= Sum + V/10 + rem(0);
];
C:= Cusip(I);
ChOut(0, C);
V:= rem( (10-rem(Sum/10)) / 10 );
return V = C-^0;
];
 
int Cusip, N;
[Cusip:= ["037833100",
"17275R102",
"38259P508",
"594918104",
"68389X106",
"68389X105"];
for N:= 0 to 6-1 do
[Text(0, if Valid(Cusip(N))
then " is valid"
else " is invalid");
CrLf(0);
];
]</lang>
 
{{out}}
<pre>
037833100 is valid
17275R102 is valid
38259P508 is valid
594918104 is valid
68389X106 is invalid
68389X105 is valid
</pre>
 
772

edits