Jump to content

CUSIP: Difference between revisions

901 bytes added ,  3 years ago
Added AutoHotkey
(Added XPL0 example.)
(Added AutoHotkey)
Line 601:
68389X106 -> false
68389X105 -> true</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>Cusip_Check_Digit(cusip){
sum := 0, i := 1, x := StrSplit(cusip)
while (i <= 8) {
c := x[i]
if c is digit
v := c
else if c is alpha
v := Asc(c) - 64 + 9
else if (c = "*")
v := 36
else if (c = "@")
v := 37
else if (c = "#")
v := 38
if (i/2 = Floor(i/2))
v *= 2
sum += Floor(v/10) + Mod(v, 10)
i++
}
return (Mod(10 - Mod(sum, 10), 10) = x[9])
}</lang>
Examples:<lang AutoHotkey>data =
(
037833100
17275R102
38259P508
594918104
68389X106
68389X105
)
 
output := "Cusip`t`tValid`n"
loop, Parse, data, `n, `r
output .= A_LoopField "`t" Cusip_Check_Digit(A_LoopField) "`n"
MsgBox % output</lang>
{{out}}
<pre>Cusip Valid
037833100 1
17275R102 1
38259P508 1
594918104 1
68389X106 0
68389X105 1</pre>
 
=={{header|AWK}}==
299

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.