RosettaCodeData/Task/CUSIP/SNOBOL4/cusip.sno

51 lines
1.3 KiB
Plaintext

#!/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