RosettaCodeData/Task/CUSIP/00-TASK.txt

50 lines
1.7 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<br/>
A &nbsp; '''CUSIP''' &nbsp; is a nine-character alphanumeric code that identifies a North American financial security for the purposes of facilitating clearing and settlement of trades. The CUSIP was adopted as an American National Standard under Accredited Standards X9.6.
;Task:
Ensure the last digit &nbsp; (i.e., the &nbsp; ''check digit'') &nbsp; of the '''CUSIP''' code (the 1<sup>st</sup> column) is correct, against the following:
* &nbsp; 037833100 &nbsp; &nbsp; &nbsp; Apple Incorporated
* &nbsp; 17275R102 &nbsp; &nbsp; &nbsp; Cisco Systems
* &nbsp; 38259P508 &nbsp; &nbsp; &nbsp; Google Incorporated
* &nbsp; 594918104 &nbsp; &nbsp; &nbsp; Microsoft Corporation
* &nbsp; 68389X106 &nbsp; &nbsp; &nbsp; Oracle Corporation &nbsp; (''incorrect'')
* &nbsp; 68389X105 &nbsp; &nbsp; &nbsp; Oracle Corporation
;Example pseudo-code below.
<syntaxhighlight lang=text>algorithm Cusip-Check-Digit(cusip) is
Input: an 8-character CUSIP
sum := 0
for 1 ≤ i ≤ 8 do
c := the ith character of cusip
if c is a digit then
v := numeric value of the digit c
else if c is a letter then
p := ordinal position of c in the alphabet (A=1, B=2...)
v := p + 9
else if c = "*" then
v := 36
else if c = "@" then
v := 37
else if' c = "#" then
v := 38
end if
if i is even then
v := v × 2
end if
sum := sum + int ( v div 10 ) + v mod 10
repeat
return (10 - (sum mod 10)) mod 10
end function</syntaxhighlight>
;See related tasks:
* [[SEDOLs|SEDOL]]
* [[Validate_International_Securities_Identification_Number|ISIN]]
<br>