How to resolve the algorithm CUSIP step by step in the SNOBOL4 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm CUSIP step by step in the SNOBOL4 programming language
Table of Contents
Problem Statement
A CUSIP 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.
Ensure the last digit (i.e., the check digit) of the CUSIP code (the 1st column) is correct, against the following:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm CUSIP step by step in the SNOBOL4 programming language
Source code in the snobol4 programming language
#!/usr/local/bin/snobol4 -r
* cusip.sno
* -- Committee on Uniform Security Identification Procedures
* -r : read data placed after the end label.
* Verify check digit and size of cusip code.
define("cusipt()i") :(cusipt_end)
cusipt
chars = &digits &ucase "*@#"
cusipt = table()
i = 0
cusipt_1
chars pos(i) len(1) . c :f(return)
cusipt[c] = i
i = i + 1 :(cusipt_1)
cusipt_end
define("check_cusip(line)c,i") :(check_cusip_end)
check_cusip
eq(size(line), 9) :f(freturn)
check_cusip = 0
i = 0
check_cusip_1
line pos(i) len(1) . c
value = t[c]
value = eq(remdr(i, 2), 1) t[c] * 2
check_cusip = check_cusip + (value / 10) + remdr(value, 10)
i = lt(i, 7) i + 1 :s(check_cusip_1)
check_cusip = remdr(10 - remdr(check_cusip, 10), 10)
eq(substr(line, 9, 1), check_cusip) :s(return)f(freturn)
check_cusip_end
*** main ***
t = cusipt()
read line = input :f(end)
check_cusip(line) :f(bad_cusip)
output = line " valid." :(read)
bad_cusip
output = line " not valid." :(read)
end
037833100
17275R102
38259P508
594918104
68389X106
68389X105
68389X10
68389X1059
68389x105
You may also check:How to resolve the algorithm Arrays step by step in the C++ programming language
You may also check:How to resolve the algorithm Magic squares of odd order step by step in the Maxima programming language
You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the Clean programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the F# programming language
You may also check:How to resolve the algorithm Stack step by step in the Java programming language