How to resolve the algorithm SEDOLs step by step in the langur programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm SEDOLs step by step in the langur programming language
Table of Contents
Problem Statement
For each number list of 6-digit SEDOLs, calculate and append the checksum digit.
That is, given this input: Produce this output: Check each input is correctly formed, especially with respect to valid characters allowed in a SEDOL string.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm SEDOLs step by step in the langur programming language
Source code in the langur programming language
val .csd = f(.code) {
given len(.code) {
case 0:
return "nada, zip, zilch"
case != 6:
return "invalid length"
}
if matching(re/[^B-DF-HJ-NP-TV-Z0-9]/, .code) {
return "invalid character(s)"
}
val .weight = [1,3,1,7,3,9]
val .nums = s2n .code
val .sum = for[=0] .i of .nums {
_for += .nums[.i] x .weight[.i]
}
toString 9 - (.sum - 1) rem 10
}
val .h = h{
# invalid...
"": 0,
"123": 0,
"A00030": 0,
"E00030": 0,
"I00030": 0,
"O00030": 0,
"U00030": 0,
"β00030": 0,
# valid...
"710889": 9,
"B0YBKJ": 7,
"406566": 3,
"B0YBLH": 2,
"228276": 5,
"B0YBKL": 9,
"557910": 7,
"B0YBKR": 5,
"585284": 2,
"B0YBKT": 7,
"B00030": 0,
}
for .input in sort(keys .h) {
val .d = .csd(.input)
if len(.d) > 1 {
writeln .input, ": ", .d
} else {
val .expect = toString .h[.input]
write .input, .d
writeln if .expect == .d {""} else {
$" (SEDOL test failed; expected check digit \.expect;)"}
}
}
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the J programming language
You may also check:How to resolve the algorithm Animate a pendulum step by step in the VBScript programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Scilab programming language
You may also check:How to resolve the algorithm Word wheel step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Nth root step by step in the NewLISP programming language