Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/CUSIP/Nanoquery/cusip.nanoquery
Normal file
38
Task/CUSIP/Nanoquery/cusip.nanoquery
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
def cusip_checksum(cusip)
|
||||
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
num = "0123456789"
|
||||
sum = 0
|
||||
|
||||
for i in range(1, 8)
|
||||
c = cusip[i - 1]
|
||||
v = 0
|
||||
if c in num
|
||||
v = int(c)
|
||||
else if c in alpha
|
||||
p = alpha[c] + 1
|
||||
v = p + 9
|
||||
else if c in "*@#"
|
||||
v = "*@#"[c] + 36
|
||||
end
|
||||
if (i % 2) = 0
|
||||
v *= 2
|
||||
end
|
||||
|
||||
sum += int(v / 10) + (v % 10)
|
||||
end
|
||||
|
||||
return (10 - (sum % 10)) % 10
|
||||
end
|
||||
|
||||
if main
|
||||
codes = {"037833100", "17275R102", "38259P508",\
|
||||
"594918104", "68389X106", "68389X105"}
|
||||
|
||||
for code in codes
|
||||
if int(code[len(code) - 1]) = cusip_checksum(code)
|
||||
println code + " is valid"
|
||||
else
|
||||
println code + " is invalid"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue