Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/CUSIP/Mathematica/cusip.math
Normal file
23
Task/CUSIP/Mathematica/cusip.math
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
ClearAll[Cusip]
|
||||
rules = Thread[(ToString /@ Range[0, 9]) -> Range[0, 9]]~Join~
|
||||
Thread[CharacterRange["A", "Z"] -> Range[26] + 9]~Join~
|
||||
Thread[Characters["*@#"] -> {36, 37, 38}];
|
||||
Cusip[cusip_String] := Module[{s = cusip, sum = 0, c, value, check},
|
||||
If[StringLength[s] != 9,
|
||||
Print["Cusip must be 9 characters!"];
|
||||
False
|
||||
,
|
||||
s = Characters[ToUpperCase[s]];
|
||||
Do[
|
||||
c = s[[i]];
|
||||
value = c /. rules;
|
||||
If[EvenQ[i], value *= 2];
|
||||
sum += Floor[value/10] + Mod[value, 10];
|
||||
,
|
||||
{i, 8}
|
||||
];
|
||||
check = Mod[(10 - Mod[sum, 10]), 10];
|
||||
s[[-1]] === ToString[check]
|
||||
]
|
||||
]
|
||||
Cusip /@ {"037833100", "17275R102", "38259P508", "594918104", "68389X106", "68389X105"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue