SEDOLs: Difference between revisions

26,751 bytes added ,  16 days ago
m
m (→‎{{header|Langur}}: implicit range with series())
(47 intermediate revisions by 21 users not shown)
Line 42:
*   [[Calculate International Securities Identification Number|ISIN]]
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">F char2value(c)
assert(c !C ‘AEIOU’, ‘No vowels’)
R Int(c, radix' 36)
 
V sedolweight = [1, 3, 1, 7, 3, 9]
 
F checksum(sedol)
V tmp = sum(zip(sedol, :sedolweight).map((ch, weight) -> char2value(ch) * weight))
R String((10 - (tmp % 10)) % 10)
 
V sedols =
|‘710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT’
 
L(sedol) sedols.split("\n")
print(sedol‘’checksum(sedol))</syntaxhighlight>
 
{{out}}
<pre>
7108899
B0YBKJ7
4065663
B0YBLH2
2282765
B0YBKL9
5579107
B0YBKR5
5852842
B0YBKT7
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">INT FUNC SedolChecksum(CHAR ARRAY sedol)
BYTE ARRAY weights=[1 3 1 7 3 9]
INT i,sum
CHAR c
 
IF sedol(0)#6 THEN
RETURN (-1)
FI
 
sum=0
FOR i=1 TO sedol(0)
DO
c=sedol(i)
IF c>='0 AND c<='9 THEN
sum==+(c-'0)*weights(i-1)
ELSE
IF c>='a AND c<='z THEN
c==-'a-'A
FI
IF c='A OR c='E OR c='I OR c='O OR c='U THEN
RETURN (-1)
ELSEIF c>='A AND c<='Z THEN
sum==+(c-'A+10)*weights(i-1)
ELSE
RETURN (-1)
FI
FI
OD
sum=(10-(sum MOD 10)) MOD 10
RETURN (sum)
 
PROC Test(CHAR ARRAY sedol)
INT res
 
res=SedolChecksum(sedol)
Print(sedol) Print(" -> ")
IF res>=0 THEN
Print(sedol) PrintIE(res)
ELSE
PrintE("invalid input")
FI
RETURN
 
PROC Main()
Test("710889")
Test("B0YBKJ")
Test("406566")
Test("B0YBLH")
Test("228276")
Test("B0YBKL")
Test("557910")
Test("B0YBKR")
Test("585284")
Test("B0YBKT")
Test("B00030")
Test("12345A")
Test("12345")
Test("1234567")
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/SEDOLs.png Screenshot from Atari 8-bit computer]
<pre>
710889 -> 7108899
B0YBKJ -> B0YBKJ7
406566 -> 4065663
B0YBLH -> B0YBLH2
228276 -> 2282765
B0YBKL -> B0YBKL9
557910 -> 5579107
B0YBKR -> B0YBKR5
585284 -> 5852842
B0YBKT -> B0YBKT7
B00030 -> B000300
12345A -> invalid input
12345 -> invalid input
1234567 -> invalid input
</pre>
 
=={{header|ActionScript}}==
<langsyntaxhighlight ActionScriptlang="actionscript">//Return the code corresponding to a given character.
//ActionScript does not have a character type, so 1-digit strings
//are used instead
Line 93 ⟶ 214:
printWithCheck("585284");
printWithCheck("B0YBKT");
printWithCheck("B00030");</langsyntaxhighlight>
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;
 
procedure Test_SEDOL is
Line 135 ⟶ 256:
Put_Line (Test (Index) & Character'Val (Character'Pos ('0') + Check (Test (Index))));
end loop;
end Test_SEDOL;</langsyntaxhighlight>
The function Check raises Constraint_Error upon an invalid input. The calculated sum is trimmed using (-''sum'') mod 10, which is mathematically equivalent to (10 - (''sum'' mod 10)) mod 10.
 
Line 153 ⟶ 274:
{{trans|C}}
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386 - ''char in string'', ''is alpha'', ''is digit'' and ''to upper'' are not in the standard's prelude}}
<langsyntaxhighlight lang="algol68">[]INT sedol weights = (1, 3, 1, 7, 3, 9);
STRING reject = "AEIOUaeiou";
Line 210 ⟶ 331:
OD;
done: SKIP
)</langsyntaxhighlight>
Output:
<pre>7108899
Line 224 ⟶ 345:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% returns the check digit for the specified SEDOL %
string(1) procedure sedolCheckDigit ( string(6) value sedol ) ;
Line 266 ⟶ 387:
testCheckDigit( "B0YBKT", "7" );
testCheckDigit( "B00030", "0" )
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 281 ⟶ 402:
B000300
</pre>
 
=={{header|AppleScript}}==
 
<syntaxhighlight lang="applescript">on appendCheckDigitToSEDOL(sedol)
if ((count sedol) is not 6) then ¬
return {false, "Error in appendCheckDigitToSEDOL handler: " & sedol & " doesn't have 6 characters."}
set chars to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set vowels to "AEIOU"
set weights to {1, 3, 1, 7, 3, 9}
set s to 0
considering diacriticals but ignoring case -- In case these are set otherwise when this handler's called.
repeat with i from 1 to 6
set thisCharacter to character i of sedol
set o to (offset of thisCharacter in chars)
if ((o is 0) or (thisCharacter is in vowels)) then ¬
return {false, "Error in appendCheckDigitToSEDOL handler: " & sedol & " contains invalid character(s)."}
set s to s + (o - 1) * (item i of weights)
end repeat
end considering
return {true, sedol & ((10 - (s mod 10)) mod 10)}
end appendCheckDigitToSEDOL
 
-- Test code:
set input to "710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030"
set output to {}
repeat with thisSEDOL in paragraphs of input
set {valid, theResult} to appendCheckDigitToSEDOL(thisSEDOL)
set end of output to theResult
end repeat
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set output to output as text
set AppleScript's text item delimiters to astid
return output</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">"7108899
B0YBKJ7
4065663
B0YBLH2
2282765
B0YBKL9
5579107
B0YBKR5
5852842
B0YBKT7
B000300"</syntaxhighlight>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">ord0: to :integer `0`
ord7: to :integer `7`
c2v: function [c][
ordC: to :integer c
if? c < `A` -> return ordC - ord0
else -> return ordC - ord7
]
 
weight: [1 3 1 7 3 9]
 
checksum: function [sedol][
val: new 0
loop .with:'i sedol 'ch ->
'val + weight\[i] * c2v ch
return to :char ord0 + (10 - val % 10) % 10
]
 
sedols: [
"710889" "B0YBKJ" "406566" "B0YBLH"
"228276" "B0YBKL" "557910" "B0YBKR"
"585284" "B0YBKT" "B00030"
]
 
loop sedols 'sed ->
print [sed "->" sed ++ checksum sed]</syntaxhighlight>
 
{{out}}
 
<pre>710889 -> 7108899
B0YBKJ -> B0YBKJ7
406566 -> 4065663
B0YBLH -> B0YBLH2
228276 -> 2282765
B0YBKL -> B0YBKL9
557910 -> 5579107
B0YBKR -> B0YBKR5
585284 -> 5852842
B0YBKT -> B0YBKT7
B00030 -> B000300</pre>
 
=={{header|AutoHotkey}}==
Line 286 ⟶ 508:
 
===Full===
<langsyntaxhighlight AutoHotkeylang="autohotkey">codes = 710889,B0YBKJ,406566,B0YBLH,228276,B0YBKL,557910,B0YBKR,585284,B0YBKT,B00030,ABCDEF,BBBBBBB
Loop, Parse, codes, `,
output .= A_LoopField "`t-> " SEDOL(A_LoopField) "`n"
Line 304 ⟶ 526:
Return "Invalid character."
Return code . Mod(10-Mod(check_digit,10),10)
}</langsyntaxhighlight>
 
===Short===
{{works with|AutoHotkey 1.1}}
<langsyntaxhighlight AutoHotkeylang="autohotkey">MsgBox % SEDOL("710889") ;7108899
MsgBox % SEDOL("B0YBKJ") ;B0YBKJ7
MsgBox % SEDOL("406566") ;4065663
Line 324 ⟶ 546:
s += ((c := Asc(A_LoopField)) >= 65 ? c - 65 + 10 : c - 48) * weights[A_Index]
return w Mod(10 - Mod(s, 10), 10)
}</langsyntaxhighlight>
 
=={{header|AWK}}==
Validate or calculate checksum of SEDOL codes read from standard input (one per line)
<langsyntaxhighlight lang="awk">function ord(a)
{
return amap[a]
Line 376 ⟶ 598:
print sedol sedolcheck
}
}</langsyntaxhighlight>
 
=={{header|BASIC}}==
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<langsyntaxhighlight lang="qbasic">DECLARE FUNCTION getSedolCheckDigit! (str AS STRING)
DO
INPUT a$
Line 410 ⟶ 633:
NEXT i
getSedolCheckDigit = (10 - (total MOD 10)) MOD 10
END FUNCTION</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
<langsyntaxhighlight lang="bbcbasic"> PRINT FNsedol("710889")
PRINT FNsedol("B0YBKJ")
PRINT FNsedol("406566")
Line 433 ⟶ 656:
s% += (a% + 7 * (a% > 9)) * weights%(i%)
NEXT
= d$ + CHR$(&30 + (10 - s% MOD 10) MOD 10)</langsyntaxhighlight>
'''Output:'''
<pre>
Line 452 ⟶ 675:
'''Notes''': it reads the codes from standard input, one per line (linefeed terminated); the input encoding must meet the following specifications: single byte encoding, digits (0-9) must have codes that follow the same order of the digits (0, 1, 2, ...) and similar for letters, the encoding must match the one used with the compiled source (likely, ASCII based encodings). This should happen 99% of the time (for ASCII, ISO-8859 family and UTF-8 have the same byte encoding for alphanumeric characters).
 
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <ctype.h>
#include <string.h>
Line 499 ⟶ 722:
}
return 0;
}</langsyntaxhighlight>
 
Fed the input list from the task description, the output is:
Line 513 ⟶ 736:
5852842
B0YBKT7</pre>
 
=={{header|C sharp|C#}}==
<syntaxhighlight lang="csharp">static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
 
if (len == 7) //SEDOL code already checksummed?
return (int)sedol[6];
 
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+")) //invalid SEDOL
return -1;
 
for (int i = 0; i < 6; i++)
{
if (Char.IsDigit(sedol[i]))
sum += (((int)sedol[i] - 48) * sedol_weights[i]);
 
else if (Char.IsLetter(sedol[i]))
sum += (((int)Char.ToUpper(sedol[i]) - 55) * sedol_weights[i]);
 
else
return -1;
 
}
 
return (10 - (sum % 10)) % 10;
}</syntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">
#include <numeric>
#include <cctype>
Line 559 ⟶ 811:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
<lang csharp>static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 };
static int sedolChecksum(string sedol)
{
int len = sedol.Length;
int sum = 0;
 
if (len == 7) //SEDOL code already checksummed?
return (int)sedol[6];
 
if ((len > 7) || (len < 6) || System.Text.RegularExpressions.Regex.IsMatch(sedol, "[AEIOUaeiou]+")) //invalid SEDOL
return -1;
 
for (int i = 0; i < 6; i++)
{
if (Char.IsDigit(sedol[i]))
sum += (((int)sedol[i] - 48) * sedol_weights[i]);
 
else if (Char.IsLetter(sedol[i]))
sum += (((int)Char.ToUpper(sedol[i]) - 55) * sedol_weights[i]);
 
else
return -1;
 
}
 
return (10 - (sum % 10)) % 10;
}</lang>
 
=={{header|Caché ObjectScript}}==
 
<langsyntaxhighlight lang="cos">Class Utils.Check [ Abstract ]
{
 
Line 610 ⟶ 833:
}
 
}</langsyntaxhighlight>
{{out|Examples}}
<pre>USER>For { Read s Quit:s="" Write ": "_##class(Utils.Check).SEDOL(s), ! }
Line 628 ⟶ 851:
 
=={{header|Clojure}}==
<langsyntaxhighlight Clojurelang="clojure">(defn sedols [xs]
(letfn [(sedol [ys] (let [weights [1 3 1 7 3 9]
convtonum (map #(Character/getNumericValue %) ys)
check (-> (reduce + (map * weights convtonum)) (rem 10) (->> (- 10)) (rem 10))]
(str ys check)))]
(map #(sedol %) xs)))</langsyntaxhighlight>
 
=={{header|COBOL}}==
{{works with|GNU Cobol|2.0}}
<langsyntaxhighlight lang="cobol"> >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. sedol.
Line 715 ⟶ 938:
CLOSE sedol-file
.
END PROGRAM sedol.</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
Implemented from scratch using the description on Wikipedia as specification.
{{Works with|ClozureCL}}
<langsyntaxhighlight lang="lisp">(defun append-sedol-check-digit (sedol &key (start 0) (end (+ start 6)))
(assert (<= 0 start end (length sedol)))
(assert (= (- end start) 6))
Line 731 ⟶ 954:
(head (subseq sedol start end))
(tail (digit-char posn)))
(return (concatenate 'string head (list tail))))))</langsyntaxhighlight>
 
=={{header|D}}==
===Functional Version===
<langsyntaxhighlight lang="d">import std.stdio, std.algorithm, std.string, std.numeric, std.ascii;
 
char checksum(in char[] sedol) pure @safe /*@nogc*/
Line 754 ⟶ 977:
B0YBKL 557910 B0YBKR 585284 B0YBKT".split)
writeln(sedol, sedol.checksum);
}</langsyntaxhighlight>
{{out}}
<pre>7108899
Line 769 ⟶ 992:
===Imperative Version===
Longer, faster lower-level version, same output.
<langsyntaxhighlight lang="d">import std.stdio, std.algorithm, std.string, std.numeric, std.ascii;
 
char sedolChecksum(in char[] sedol) pure nothrow @safe /*@nogc*/
Line 806 ⟶ 1,029:
"585284", "B0YBKT"])
writeln(s, s.sedolChecksum);
}</langsyntaxhighlight>
 
===Short Version===
Same output.
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.algorithm, std.string, std.numeric,std.ascii;
 
Line 818 ⟶ 1,041:
.map!(c => c.isDigit ? c - '0' : c - 'A' + 10)
.dotProduct([1, 3, 1, 7, 3, 9]) % 10);
}</langsyntaxhighlight>
 
=={{header|Delphi}}==
 
<langsyntaxhighlight Delphilang="delphi">program Sedol;
 
{$APPTYPE CONSOLE}
Line 901 ⟶ 1,124:
readln;
end.
</syntaxhighlight>
</lang>
 
Output:
Line 917 ⟶ 1,140:
 
=={{header|E}}==
<langsyntaxhighlight lang="e">def weights := [1,3,1,7,3,9]
def Digit := ('0'..'9')
def Letter := ('B'..'D'|'F'..'H'|'J'..'N'|'P'..'T'|'V'..'Z')
Line 953 ⟶ 1,176:
B0YBKT".trim().split("\n") {
println(addChecksum(sedol.trim()))
}</langsyntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
weights[] = [ 1 3 1 7 3 9 ]
func$ chksum sedol6$ .
if len sedol6$ <> 6
return ""
.
for i to 6
c$ = substr sedol6$ 1 1
if strpos "AEIOU" c$ <> 0
return ""
.
h = strcode substr sedol6$ i 1
if h >= 48 and h <= 57
h -= 48
elif h >= 65 and h <= 90
h -= 65 - 10
else
return ""
.
sum += h * weights[i]
.
return strchar ((10 - (sum mod 10)) mod 10 + 48)
.
repeat
s$ = input
until s$ = ""
print s$ & chksum s$
.
input_data
710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
</syntaxhighlight>
 
=={{header|Elixir}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="elixir">defmodule SEDOL do
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints
@sedolweight [1,3,1,7,3,9]
Line 999 ⟶ 1,265:
e in ArgumentError -> IO.inspect e
end
end)</langsyntaxhighlight>
 
{{out}}
Line 1,019 ⟶ 1,285:
</pre>
 
=={{header|Excel VBA}}==
===LAMBDA===
<lang lb>
 
Function getSedolCheckDigit(Input1)
Defining a reusable Excel function by binding the name SEDOLCHECKSUM to a lambda expression in the Name Manager of the Excel worksheet:
Dim mult(6) As Integer
 
mult(1) = 1: mult(2) = 3: mult(3) = 1
(See [https://www.microsoft.com/en-us/research/blog/lambda-the-ultimatae-excel-worksheet-function/ LAMBDA: The ultimate Excel worksheet function])
mult(4) = 7: mult(5) = 3: mult(6) = 9
 
If Len(Input1) <> 6 Then
{{Works with|Office 365 Betas 2021}}
getSedolCheckDigit = "Six chars only please"
 
Exit Function
<syntaxhighlight lang="lisp">SEDOLCHECKSUM
End If
=LAMBDA(s,
Input1 = UCase(Input1)
TotalIF(6 = 0LEN(s),
For i = 1 To 6LET(
s1 = Mid cs, MID(Input1s, iSEQUENCE(1, 6, 1, 1), 1),
isVowel, LAMBDA(c,
If (s1 = "A") Or (s1 = "E") Or (s1 = "I") Or (s1 = "O") Or (s1 = "U") Then
getSedolCheckDigit = ELEM(c)({"No vowelsA","E","I","O","U"})
Exit Function),
End If sedolValue, LAMBDA(c,
If (Asc(s1) >= 48) And (Asc(s1) <= 57) ThenLET(
Total = Total + Val(s1) *ic, multCODE(ic),
Else IF(65 > ic,
Total = Total + (Asc(s1) - 55) * mult(i)ic - 48,
End If (ic + 10) - 65
)
Next i )
),
getSedolCheckDigit = Input1 + CStr((10 - (Total Mod 10)) Mod 10)
IF(OR(isVowel(cs)),
" -> Invalid vowel in SEDOL string",
End Function
MOD(
</lang>
10 - MOD(
SUM(
MUL({1,3,1,7,3,9})(
sedolValue(cs)
)
), 10
), 10
)
)
),
"Expected a 6-character SEDOL"
)
)</syntaxhighlight>
 
and also assuming that the names ELEM and MUL are bound to the following reusable lambdas in Name Manager:
 
<syntaxhighlight lang="lisp">ELEM
=LAMBDA(x,
LAMBDA(xs,
ISNUMBER(MATCH(x, xs, 0))
)
)
 
 
MUL
=LAMBDA(a, LAMBDA(b, a * b))</syntaxhighlight>
{{Out}}
 
The appended value in cell C2 results from the expression '''=A2 & B2'''
 
{| class="wikitable"
|-
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx
! colspan="4" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=SEDOLCHECKSUM(A2)
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;"
|
| A
| B
| C
| D
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1
| style="text-align:right; font-weight:bold" | Sedols
| style="font-weight:bold" | Checksums
| style="text-align:left; font-weight:bold" | Appended
| style="font-weight:bold" |
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| style="text-align:right; font-weight:bold" | 710889
| style="background-color:#cbcefb;" | 9
| style="text-align:left;" | 7108899
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| style="text-align:right; font-weight:bold" | B0YBKJ
| 7
| style="text-align:left;" | B0YBKJ7
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4
| style="text-align:right; font-weight:bold" | 406566
| 3
| style="text-align:left;" | 4065663
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 5
| style="text-align:right; font-weight:bold" | B0YBLH
| 2
| style="text-align:left;" | B0YBLH2
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 6
| style="text-align:right; font-weight:bold" | 228276
| 5
| style="text-align:left;" | 2282765
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 7
| style="text-align:right; font-weight:bold" | B0YBKL
| 9
| style="text-align:left;" | B0YBKL9
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 8
| style="text-align:right; font-weight:bold" | 557910
| 7
| style="text-align:left;" | 5579107
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 9
| style="text-align:right; font-weight:bold" | B0YBKR
| 5
| style="text-align:left;" | B0YBKR5
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 10
| style="text-align:right; font-weight:bold" | 585284
| 2
| style="text-align:left;" | 5852842
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 11
| style="text-align:right; font-weight:bold" | B0YBKT
| 7
| style="text-align:left;" | B0YBKT7
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 12
| style="text-align:right; font-weight:bold" | B00030
| 0
| style="text-align:left;" | B000300
|
|- style="text-align:right;"
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 13
| style="text-align:right; font-weight:bold" | BOYBKT
| -> Invalid vowel in SEDOL string
| style="text-align:left;" | BOYBKT -> Invalid vowel in SEDOL string
|
|}
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL"
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"]
Line 1,077 ⟶ 1,462:
addCheckDigit Inputs |> List.iter (printfn "%s")
with
ex -> printfn "ERROR: %s" ex.Message</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: combinators combinators.short-circuit formatting io kernel
math math.parser regexp sequences unicode ;
IN: rosetta-code.sedols
Line 1,121 ⟶ 1,506:
input [ dup sedol-check-digit "%-6s %s\n" printf ] each ;
 
MAIN: sedol-demo</langsyntaxhighlight>
{{out}}
<pre>
Line 1,144 ⟶ 1,529:
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">create weight 1 , 3 , 1 , 7 , 3 , 9 ,
 
: char>num ( '0-9A-Z' -- 0..35 )
Line 1,171 ⟶ 1,556:
sedol" B0YBKR" B0YBKR5 ok
sedol" 585284" 5852842 ok
sedol" B0YBKT" B0YBKT7 ok</langsyntaxhighlight>
 
=={{header|Fortran}}==
{{Works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran">MODULE SEDOL_CHECK
IMPLICIT NONE
CONTAINS
Line 1,217 ⟶ 1,602:
END DO
END PROGRAM SEDOLTEST</langsyntaxhighlight>
Output
710889 7108899
Line 1,231 ⟶ 1,616:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight FreeBASIClang="freebasic">' version 05-07-2015
' compile with: fbc -s console
 
Line 1,323 ⟶ 1,708:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>Calculated checksum
Line 1,361 ⟶ 1,746:
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=905f91c785f1f15a360726717731862f Click this link to run this code]'''
<langsyntaxhighlight lang="gambas">Public Sub Main()
Dim byWeight As Byte[] = [1, 3, 1, 7, 3, 9, 1]
Dim byCount, byCompute As Byte
Line 1,389 ⟶ 1,774:
Next
 
End</langsyntaxhighlight>
Output:
<pre>
Line 1,404 ⟶ 1,789:
B00030 = B000300
</pre>
 
=={{header|Go}}==
<syntaxhighlight lang="go">
<lang go>
package main
 
Line 1,468 ⟶ 1,854:
}
}
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,496 ⟶ 1,882:
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">def checksum(text) {
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text"
 
Line 1,505 ⟶ 1,891:
text + (10 - (sum % 10)) % 10
}
String.metaClass.sedol = { this.&checksum(delegate) }</langsyntaxhighlight>
Test Code:
<langsyntaxhighlight lang="groovy">[ '710889': '7108899', 'B0YBKJ': 'B0YBKJ7', '406566': '4065663', 'B0YBLH': 'B0YBLH2',
'228276': '2282765', 'B0YBKL': 'B0YBKL9', '557910': '5579107', 'B0YBKR': 'B0YBKR5',
'585284': '5852842', 'B0YBKT': 'B0YBKT7', 'B00030': 'B000300'].each { text, expected ->
println "Checking $text -> $expected"
assert expected == text.sedol()
}</langsyntaxhighlight>
Output:
<pre>Checking 710889 -> 7108899
Line 1,527 ⟶ 1,913:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Char (isDigitisAsciiUpper, isAsciiUpperisDigit, ord)
 
-------------------------- SEDOLS ------------------------
 
checkSum :: String -> String
checkSum x =
case traverse sedolValue x of
show .
Right xs -> (show . checkSumFromSedolValues) xs
(`rem` 10) .
Left annotated -> annotated
(-) 10 . (`rem` 10) . sum . zipWith (*) [1, 3, 1, 7, 3, 9] . fmap charValue
 
checkSumFromSedolValues :: [Int] -> Int
checkSumFromSedolValues xs =
rem
( 10
- rem
( sum $
zipWith
(*)
[1, 3, 1, 7, 3, 9]
xs
)
10
)
10
 
charValuesedolValue :: Char -> Either String Int
sedolValue c
charValue c
| c `elem` "AEIOU" = errorLeft "No vowels← Unexpected vowel."
| isDigit c = Right (ord c - ord '0')
| isAsciiUpper c = Right (ord c - ord 'A' + 10)
 
-- TEST --------------------------------------------- TEST -------------------------
main :: IO ()
main =
mapM_
(putStrLn . ((++<>) <*> checkSum))
[ "710889",
, "B0YBKJ",
, "406566",
, "B0YBLH",
, "228276",
, "B0YBKL",
, "557910",
, "B0YBKR",
, "585284",
, "B0YBKT",
"BOYBKT", -- Ill formed test case - illegal vowel.
, "B00030"
]</lang> "B00030"
]</syntaxhighlight>
{{Out}}
<pre>7108899
Line 1,569 ⟶ 1,973:
5852842
B0YBKT7
BOYBKT ← Unexpected vowel.
B000300</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">procedure main()
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"|
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030"))
Line 1,590 ⟶ 1,995:
return x || (10 - (t%10)) % 10 # complete
}
end</langsyntaxhighlight>
 
=={{header|J}}==
There are several ways to perform this in J. This most closely follows the algorithmic description at Wikipedia:
<langsyntaxhighlight lang="j">sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)</langsyntaxhighlight>
However, because J is so concise, having written the above, it becomes clear that the negation (<tt>-</tt>) is unnecessary.
 
Line 1,601 ⟶ 2,006:
 
Which leads us to this more efficient formulation:
<langsyntaxhighlight lang="j">ac1 =: (, 10 | (10 - 1 3 1 7 3 9) +/@:* ])&.(sn i. |:)</langsyntaxhighlight>
which reduces to:
<langsyntaxhighlight lang="j">ac2 =: (, 10 | 9 7 9 3 7 1 +/@:* ])&.(sn i. |:)</langsyntaxhighlight>
Which is just as concise as <tt>ac0</tt>, but faster.
 
Line 1,609 ⟶ 2,014:
 
Which leads us to:
<langsyntaxhighlight lang="j">ac3 =: (,"1 0 (841 $ '0987654321') {~ 1 3 1 7 3 9 +/ .*~ sn i. ])</langsyntaxhighlight>
Which is more than twice as fast as even the optimized formulation (<tt>ac2</tt>), though it is slightly longer.
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">import java.util.Scanner;
 
public class SEDOL{
Line 1,643 ⟶ 2,048:
return (str.length() == 6) && !str.toUpperCase().matches(".*?[AEIOU].*?");
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
===Imperative===
<langsyntaxhighlight lang="javascript">function sedol(input) {
return input + sedol_check_digit(input);
}
Line 1,687 ⟶ 2,092:
print("error: " + e);
}
}</langsyntaxhighlight>
output
<pre>7108899
Line 1,705 ⟶ 2,110:
 
===Functional===
<langsyntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 1,868 ⟶ 2,273:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>7108899
Line 1,885 ⟶ 2,290:
{{works with|jq|1.4}}
This implementation accepts strings with lowercase letters, but converts them to uppercase.
<langsyntaxhighlight lang="jq">def ascii_upcase:
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;
 
Line 1,927 ⟶ 2,332:
else $ans
end ;
sedolize</langsyntaxhighlight>
{{Out}}
# Assuming sedol.txt contains the input in the task description
Line 1,936 ⟶ 2,341:
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">using Base.Test
 
function appendchecksum(chars::AbstractString)
Line 1,956 ⟶ 2,361:
@test appendchecksum(t) == c
end
end</langsyntaxhighlight>
 
{{out}}
Line 1,963 ⟶ 2,368:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="kotlin">
<lang scala>// version 1.1.0
val weights = arrayOf(1, 3, 1, 7, 3, 9, 1)
val validChars = (('0'..'9') + ('A'..'Z')).toSet() - "AEIOU".toSet()
 
fun sedol7(sedol6: String): String {
val weights = listOf(1, 3, 1, 7, 3, 9, 1)
require(sedol6.length == 6) { "Length of argument string must be 6" }
require(sedol6.all { it in validChars }) { "Argument string contains an invalid character" }
 
val sum = sedol6.map { it.digitToInt(36) }.zip(weights, Int::times).sum()
fun sedol7(sedol6: String): String {
val check = (-sum).mod(10)
if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6")
varreturn sumsedol6 =+ ('0' + check)
for (i in 0..5) {
val c = sedol6[i]
val v = when (c) {
in '0'..'9' -> c.toInt() - 48
in 'A'..'Z' -> c.toInt() - 55
else -> throw IllegalArgumentException("Argument string contains an invalid character")
}
sum += v * weights[i]
}
val check = (10 - (sum % 10)) % 10
return sedol6 + (check + 48).toChar()
}
 
fun main(args: Array<String>) {
val sedol6s = listOf("710889", "B0YBKJ", "406566", "B0YBLH", "228276", "B0YBKL",
"710889", "557910B0YBKJ", "B0YBKR406566", "585284B0YBLH", "B0YBKT228276", "B00030B0YBKL"),
"557910", "B0YBKR", "585284", "B0YBKT", "B00030"
for (sedol6 in sedol6s) println("$sedol6 -> ${sedol7(sedol6)}")
)
}</lang>
for (sedol6 in sedol6s)
println("$sedol6 -> ${sedol7(sedol6)}")
}
</syntaxhighlight>
 
{{out}}
Line 2,004 ⟶ 2,406:
</pre>
 
=={{header|Langurlangur}}==
{{trans|Go}}
<syntaxhighlight lang="langur">val .csd = fn(.code) {
<lang Langur>val .weight = [1,3,1,7,3,9]
switch len(.code) {
 
val .csd = f(.code) {
given len(.code) {
case 0:
return "nada, zip, zilch"
Line 2,016 ⟶ 2,416:
}
 
if matching(.code -> re/[^B-DF-HJ-NP-TV-Z0-9]/, .code) {
return "invalid character(s)"
}
 
val .sumweight = foldfrom([1,3,1,7,3,9]
f(.sum, .i, .c) .sum + toNumber(.c, 36) x .weight[.i],
0,
series len .code,
split ZLS, .code,
)
 
toStringval 9 - (.sumnums -= 1)s2n rem 10.code
val .sum = for[=0] .i of .nums {
_for += .nums[.i] * .weight[.i]
}
 
string 9 - (.sum - 1) rem 10
}
 
val .h = h{
# invalid...
"": 0,
Line 2,060 ⟶ 2,460:
writeln .input, ": ", .d
} else {
val .expect = toStringstring .h[.input]
write .input, .d
writeln if .expect == .d {""} else {
$" (SEDOL test failed; expected check digit \.expect;)"}
}
}
}</lang>
</syntaxhighlight>
 
{{out}}
Line 2,090 ⟶ 2,491:
 
=={{header|Liberty BASIC}}==
<syntaxhighlight lang="lb">
<lang lb>
'adapted from BASIC solution
mult(1) = 1: mult(2) = 3: mult(3) = 1
Line 2,122 ⟶ 2,523:
getSedolCheckDigit = (10 - (total MOD 10)) MOD 10
END FUNCTION
</syntaxhighlight>
</lang>
 
=={{header|M4}}==
<langsyntaxhighlight M4lang="m4">divert(-1)
changequote(`[',`]')
define([_bar],include(sedol.inp))
Line 2,141 ⟶ 2,542:
])
divert
eachline(_bar,[checksum])</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">SEDOL[Code_?(Function[v,StringFreeQ[v,{"A","E","I","O","U"}]])]:=
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code]
/.x_?LetterQ->(ToCharacterCode[x]-55)]]].{1,3,1,7,3,9},10]]
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUMMY"}]</syntaxhighlight>
 
{{out}}
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUMMY"}]
<pre>
 
->Output:
7108899
B0YBKJ7
Line 2,162 ⟶ 2,562:
B0YBKT7
B0003010
SEDOL[DUMMY] -> rejected</langpre>
 
=={{header|Mercury}}==
<syntaxhighlight lang="text">:- module sedol.
:- interface.
 
Line 2,217 ⟶ 2,617:
is_vowel('I').
is_vowel('O').
is_vowel('U').</langsyntaxhighlight>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE SEDOL EXPORTS Main;
 
IMPORT IO, Fmt, Text, Stdio;
Line 2,263 ⟶ 2,663:
| BadSedol(text) => IO.Put(text & "\n", Stdio.stderr);
END;
END SEDOL.</langsyntaxhighlight>
Output:
<pre>7108899
Line 2,277 ⟶ 2,677:
 
=={{header|MUMPS}}==
<langsyntaxhighlight MUMPSlang="mumps">SEDOL
NEW A,B
SEDOL1
Line 2,297 ⟶ 2,697:
NEW UP,LO
SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ",LO="abcdefghijklmnopqrstuvwxyz"
QUIT $TRANSLATE(X,LO,UP)</langsyntaxhighlight>
Examples:
<pre>USER>D SEDOL^ROSETTA
Line 2,329 ⟶ 2,729:
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">proc c2v(c: char): int =
<lang nim>import strutils
 
proc c2v(c): int =
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
let a = ord(c)
if a < 65: a - 48
const weight = [1, 3, 1, 7, 3, 9]
else: a - 55
proc checksum(sedol: string): char =
var val = 0
for i, ch in sedol:
val += c2v(ch) * weight[i]
result = chr((10 - val mod 10) mod 10 + ord('0'))
for sedol in ["710889", "B0YBKJ", "406566", "B0YBLH",
"228276", "B0YBKL", "557910", "B0YBKR",
"585284", "B0YBKT", "B00030"]:
echo sedol, " → ", sedol & checksum(sedol)</syntaxhighlight>
 
{{out}}
const weight = [1,3,1,7,3,9]
<pre>710889 → 7108899
 
B0YBKJ → B0YBKJ7
proc checksum(sedol): string =
406566 → 4065663
var tmp = 0
B0YBLH → B0YBLH2
for i,s in sedol:
228276 → 2282765
tmp += c2v(s) * weight[i]
B0YBKL → B0YBKL9
result = $((10 - (tmp mod 10)) mod 10)
557910 → 5579107
 
B0YBKR → B0YBKR5
for sedol in """710889
585284 → 5852842
B0YBKJ
B0YBKT → B0YBKT7
406566
B00030 → B000300</pre>
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030""".splitLines():
echo sedol, checksum(sedol)</lang>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">let char2value c =
assert (not (String.contains "AEIOU" c));
match c with
Line 2,386 ⟶ 2,787:
"B0YBKR";
"585284";
"B0YBKT" ]</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">func: sedol(s)
[ 1, 3, 1, 7, 3, 9 ] s
zipWith(#[ dup isDigit ifTrue: [ '0' - ] else: [ 'A' - 10 + ] * ]) sum
10 mod 10 swap - 10 mod
StringBuffer new s << swap '0' + <<c ;</langsyntaxhighlight>
 
{{out}}
Line 2,415 ⟶ 2,816:
=={{header|Pascal}}==
{{works with|Free_Pascal}}
<langsyntaxhighlight lang="pascal">program Sedols(output);
 
function index(c: char): integer;
Line 2,459 ⟶ 2,860:
writeln(codes[i], ' -> ', seforl);
end;
end.</langsyntaxhighlight>
Output:
<pre>% ./Sedols
Line 2,476 ⟶ 2,877:
=={{header|Perl}}==
This program reads from standard input.
<langsyntaxhighlight lang="perl">use List::Util qw(sum);
use POSIX qw(strtol);
 
sub zip :prototype(&\@\@) {
my $f = shift;
my @a = @{shift()};
Line 2,489 ⟶ 2,890:
 
my @weights = (1, 3, 1, 7, 3, 9);
sub sedolsedan :prototype($) {
my $s = shift;
$s =~ /[AEIOU]/ and die "No vowels";
Line 2,501 ⟶ 2,902:
chomp;
print sedol($_), "\n";
}</langsyntaxhighlight>
 
=={{header|Perl 6}}==
{{trans|Perl}}
{{Works with|rakudo|2015-12-17}}
<lang perl6>sub sedol( Str $s ) {
die 'No vowels allowed' if $s ~~ /<[AEIOU]>/;
die 'Invalid format' if $s !~~ /^ <[0..9B..DF..HJ..NP..TV..Z]>**6 $ /;
 
my %base36 = (flat 0..9, 'A'..'Z') »=>« ^36;
my @weights = 1, 3, 1, 7, 3, 9;
 
my @vs = %base36{ $s.comb };
my $checksum = [+] @vs Z* @weights;
my $check_digit = (10 - $checksum % 10) % 10;
return $s ~ $check_digit;
}
 
say sedol($_) for <
710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
>;</lang>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>type string6(object s)
<span style="color: #008080;">type</span> <span style="color: #000000;">string6</span><span style="color: #0000FF;">(</span><span style="color: #004080;">object</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
return string(s) and length(s)=6
<span style="color: #008080;">return</span> <span style="color: #004080;">string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">6</span>
end type
<span style="color: #008080;">end</span> <span style="color: #008080;">type</span>
 
type sedolch(integer ch)
<span style="color: #008080;">type</span> <span style="color: #000000;">sedolch</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">)</span>
return ch>='0' and ch<='Z' and (ch<='9' or ch>='A') and not find(ch,"AEIOU")
<span style="color: #008080;">return</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">>=</span><span style="color: #008000;">'0'</span> <span style="color: #008080;">and</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;"><=</span><span style="color: #008000;">'Z'</span> <span style="color: #008080;">and</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">ch</span><span style="color: #0000FF;"><=</span><span style="color: #008000;">'9'</span> <span style="color: #008080;">or</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">>=</span><span style="color: #008000;">'A'</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ch</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"AEIOU"</span><span style="color: #0000FF;">)</span>
end type
<span style="color: #008080;">end</span> <span style="color: #008080;">type</span>
 
function sedol(string6 t)
<span style="color: #008080;">function</span> <span style="color: #000000;">sedol</span><span style="color: #0000FF;">(</span><span style="color: #000000;">string6</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">)</span>
sedolch c
<span style="color: #000000;">sedolch</span> <span style="color: #000000;">c</span>
integer s = 0
<span style="color: #004080;">integer</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
for i=1 to 6 do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">6</span> <span style="color: #008080;">do</span>
c = t[i]
<span style="color: #000000;">c</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
s += iff(c>='A'?c-'A'+10:c-'0')*{1,3,1,7,3,9}[i]
<span style="color: #000000;">s</span> <span style="color: #0000FF;">+=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">c</span><span style="color: #0000FF;">>=</span><span style="color: #008000;">'A'</span><span style="color: #0000FF;">?</span><span style="color: #000000;">c</span><span style="color: #0000FF;">-</span><span style="color: #008000;">'A'</span><span style="color: #0000FF;">+</span><span style="color: #000000;">10</span><span style="color: #0000FF;">:</span><span style="color: #000000;">c</span><span style="color: #0000FF;">-</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">)*{</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">7</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">}[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
return t & mod(10-mod(s,10),10)+'0'
<span style="color: #008080;">return</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">&</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">-</span><span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">),</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)+</span><span style="color: #008000;">'0'</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
 
constant tests = {"710889",
<span style="color: #008080;">constant</span> <span style="color: #000000;">tests</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"710889"</span><span style="color: #0000FF;">,</span>
"B0YBKJ",
<span style="406566color: #008000;">"B0YBKJ"</span><span style="color: #0000FF;">,</span>
<span style="B0YBLHcolor: #008000;">"406566"</span><span style="color: #0000FF;">,</span>
<span style="228276color: #008000;">"B0YBLH"</span><span style="color: #0000FF;">,</span>
<span style="B0YBKLcolor: #008000;">"228276"</span><span style="color: #0000FF;">,</span>
<span style="557910color: #008000;">"B0YBKL"</span><span style="color: #0000FF;">,</span>
<span style="B0YBKRcolor: #008000;">"557910"</span><span style="color: #0000FF;">,</span>
<span style="585284color: #008000;">"B0YBKR"</span><span style="color: #0000FF;">,</span>
<span style="B0YBKTcolor: #008000;">"585284"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"B0YBKT"</span><span style="color: #0000FF;">,</span>
"B00030"}
<span style="color: #008000;">"B00030"</span><span style="color: #0000FF;">}</span>
for i=1 to length(tests) do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
?sedol(tests[i])
<span style="color: #0000FF;">?</span><span style="color: #000000;">sedol</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span>
end for</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 2,580 ⟶ 2,953:
"B000300"
</pre>
 
=={{header|Phixmonti}}==
{{trans|RPL}}
<syntaxhighlight lang="Phixmonti">include ..\Utilitys.pmt
 
def ->7DOL
( 1 3 1 7 3 9 ) var weights
0 >ps
6 for >ps
tps get
dup 65 >= if 7 - endif 48 -
weights ps> get nip * ps> + >ps
endfor
10 ps> 10 mod - 10 mod tostr chain
enddef
 
( "710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL" "557910" "B0YBKR" "585284" "B0YBKT" "B00030" )
 
getid ->7DOL map
 
pstack</syntaxhighlight>
{{out}}
<pre>
[["7108899", "B0YBKJ7", "4065663", "B0YBLH2", "2282765", "B0YBKL9", "5579107", "B0YBKR5", "5852842", "B0YBKT7", "B000300"]]
 
=== Press any key to exit ===</pre>
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">function char2value($c) {
assert(stripos('AEIOU', $c) === FALSE);
return intval($c, 36);
Line 2,607 ⟶ 3,006:
'585284',
'B0YBKT') as $sedol)
echo $sedol, checksum($sedol), "\n";</langsyntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de sedol (Str)
(pack Str
(char
Line 2,630 ⟶ 3,029:
 
(for S '("710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL" "557910" "B0YBKR" "585284" "B0YBKT" "B00030")
(prinl (sedol S)) )</langsyntaxhighlight>
 
=={{header|PL/I}}==
<langsyntaxhighlight PLIlang="pli">/* Compute SEDOLs; includes check for invalid characters. */
sedol: procedure options (main); /* 3 March 2012 */
declare alphabet character (36) static initial
Line 2,655 ⟶ 3,054:
put edit (s, v) (x(2), a, f(1)); put edit (' ') (a);
end;
end sedol;</langsyntaxhighlight>
 
{{out}}
Line 2,674 ⟶ 3,073:
=={{header|Potion}}==
No extra credit.
<langsyntaxhighlight lang="potion">sedolnum = (c) :
if ("0" ord <= c ord and c ord <= "9" ord): c number integer.
else: 10 + c ord - "A" ord.
Line 2,686 ⟶ 3,085:
.
(str, (10 - (sum % 10)) % 10) join
.</langsyntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">function Add-SEDOLCheckDigit
{
Param ( # Validate input as six-digit SEDOL number
Line 2,736 ⟶ 3,135:
{
Add-SEDOLCheckDigit -SixDigitSEDOL $PartialSEDOL
}</langsyntaxhighlight>
{{out}}
<pre>7108899
Line 2,751 ⟶ 3,150:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">Procedure.s SEDOLs(rawstring$)
Protected i, j, sum, c, m
For i=1 To Len(rawstring$)
Line 2,790 ⟶ 3,189:
Data.s "710889","B0YBKJ","406566","B0YBLH","228276"
Data.s "B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030"
EndDataSection</langsyntaxhighlight>
 
[[Image:PB SEDOL.png]]
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">def char2value(c):
assert c not in 'AEIOU', "No vowels"
return int(c, 36)
Line 2,805 ⟶ 3,204:
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
 
for sedol in '''
Line 2,819 ⟶ 3,218:
B0YBKT
'''.split():
print sedol + checksum(sedol)</langsyntaxhighlight>
 
 
Line 2,825 ⟶ 3,224:
 
{{Works with|Python|3.7}}
<langsyntaxhighlight lang="python">'''SEDOL checksum digits'''
 
from functools import reduce
Line 2,849 ⟶ 3,248:
Right(0)
)
)(lambda d: Right(str((10 - (d % 10)) % 10)))
 
 
Line 2,949 ⟶ 3,348:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>SEDOL checksum digits:
Line 2,967 ⟶ 3,366:
 
=={{header|Q}}==
<langsyntaxhighlight lang="q">scd:{
v:{("i"$x) - ?[("0"<=x) & x<="9"; "i"$"0"; -10+"i"$"A"]} each x; / Turn characters of SEDOL into their values
w:sum v*1 3 1 7 3 9; / Weighted sum of values
Line 2,974 ⟶ 3,373:
}
 
scd each ("710889";"B0YBKJ";"406566";"B0YBLH";"228276";"B0YBKL";"557910";"B0YBKR";"585284";"B0YBKT";"B00030")</langsyntaxhighlight>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ 48 - dup 9 > if [ 7 - ] ] is chvalue ( c --> n )
[ 0 over witheach
[ chvalue
' [ 1 3 1 7 3 9 ]
i^ peek * + ]
10 mod 10 swap - 10 mod
48 + join ] is ->sedol ( $ --> $ )
$ "710889 B0YBKJ 406566 B0YBLH
228276 B0YBKL 557910 B0YBKR
585284 B0YBKT B00030" nest$
 
witheach [ ->sedol echo$ cr ]</syntaxhighlight>
 
{{out}}
 
<pre>7108899
B0YBKJ7
4065663
B0YBLH2
2282765
B0YBKL9
5579107
B0YBKR5
5852842
B0YBKT7
B000300</pre>
 
=={{header|R}}==
<langsyntaxhighlight lang="rsplus"># Read in data from text connection
datalines <- readLines(tc <- textConnection("710889
B0YBKJ
Line 3,013 ⟶ 3,443:
 
#Print in format requested
writeLines(withchkdig)</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
;;; Since the Task gives us unchecksummed and checksummed SEDOLs, and
;;; we'll just take a list of the output SEDOLs and remove their last
Line 3,078 ⟶ 3,508:
(check-false (invalid-SEDOL? S))
(check-equal? (SEDOL-append-checksum (substring S 0 6))
S (format "test SEDOL for ~a" S))))</langsyntaxhighlight>
 
Output:
Line 3,096 ⟶ 3,526:
#f
invalid checksum</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{trans|Perl}}
{{Works with|rakudo|2015-12-17}}
<syntaxhighlight lang="raku" line>sub sedol( Str $s ) {
die 'No vowels allowed' if $s ~~ /<[AEIOU]>/;
die 'Invalid format' if $s !~~ /^ <[0..9B..DF..HJ..NP..TV..Z]>**6 $ /;
 
my %base36 = (flat 0..9, 'A'..'Z') »=>« ^36;
my @weights = 1, 3, 1, 7, 3, 9;
 
my @vs = %base36{ $s.comb };
my $checksum = [+] @vs Z* @weights;
my $check_digit = (10 - $checksum % 10) % 10;
return $s ~ $check_digit;
}
 
say sedol($_) for <
710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
>;</syntaxhighlight>
 
=={{header|REXX}}==
Line 3,106 ⟶ 3,567:
╚════════════════════════════════════════════════════════════════════╝
</pre>
<langsyntaxhighlight lang="rexx">/*REXX program computes the check digit (last digit) for six or seven character SEDOLs.*/
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*the uppercase Latin alphabet. */
alphaDigs= '0123456789'@abcU /*legal characters, and then some. */
Line 3,147 ⟶ 3,608:
sed: say; say 'SEDOL:' sedol; say; return
ser: say; say '***error***' arg(1); call sed; exit 13
swa: say; say '***warning***' arg(1); say; return</langsyntaxhighlight>
'''output''' &nbsp; when using the defaults:
<pre>
Line 3,164 ⟶ 3,625:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
see sedol("710889") + nl
see sedol("B0YBKJ") + nl
Line 3,189 ⟶ 3,650:
next
return d + (10 - (s % 10)) % 10
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,203 ⟶ 3,664:
B0YBKT7
B000300
</pre>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
{ 1 3 1 7 3 9 } → weights
≪ 0 1 6 '''FOR''' j
OVER j DUP SUB NUM
'''IF''' DUP 65 ≥ '''THEN''' 7 - '''END''' 48 -
weights j GET * +
'''NEXT'''
10 SWAP OVER MOD - 10 MOD →STR +
≫ ≫ ''''→7DOL'''' STO
|
'''→7DOL''' ''( "SEDOL6" -- "SEDOL7" ) ''
store weights
sum=0 ; for j = 1 to 6
get jth character of SEDOL
convert it to its index
sum += index * weight
check = mod(10-mod(sum,10),10)
.
|}
{{in}}
<pre>
≪ { }
{ "710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL" "557910" "B0YBKR" "585284" "B0YBKT" "B00030" }
1 OVER SIZE FOR j DUP j GET →7DOL SWAP + SWAP NEXT DROP
≫ EVAL
</pre>
{{out}}
<pre>
1: { "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300" }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ"
Sedolweight = [1,3,1,7,3,9]
 
Line 3,242 ⟶ 3,742:
p e
end
end</langsyntaxhighlight>
{{out}}
<pre>
Line 3,259 ⟶ 3,759:
1234567 #<ArgumentError: Invalid length>
00000A #<ArgumentError: No vowels>
</pre>
 
=={{header|Rust}}==
<syntaxhighlight lang="rust">
fn sedol(input: &str) -> Option<String> {
let weights = vec![1, 3, 1, 7, 3, 9, 1];
let valid_chars = "0123456789BCDFGHJKLMNPQRSTVWXYZ";
 
if input.len() != 6 {
return None;
}
 
// could be done by regex if needed
for c in input.chars() {
if !valid_chars.contains(c) {
return None;
}
}
 
let mut result: u32 = input
.chars()
.map(|c| {
if c.is_digit(10) {
c as u32 - 48
} else {
c as u32 - 55
}
})
.zip(weights)
.map(|(cnum, w)| w * cnum)
.collect::<Vec<u32>>()
.iter()
.sum();
 
result = (10 - result % 10) % 10;
 
Some(input.to_owned() + &result.to_string())
}
 
fn main() {
let inputs = vec![
"710889", "B0YBKJ", "406566", "B0YBLH", "228276", "B0YBKL", "557910", "B0YBKR", "585284",
"B0YBKT", "B00030",
];
 
for input in inputs {
println!("{} SEDOL: {:?}", &input, sedol(&input).unwrap());
}
}
 
</syntaxhighlight>
{{out}}
<pre>
710889 SEDOL: "7108899"
B0YBKJ SEDOL: "B0YBKJ7"
406566 SEDOL: "4065663"
B0YBLH SEDOL: "B0YBLH2"
228276 SEDOL: "2282765"
B0YBKL SEDOL: "B0YBKL9"
557910 SEDOL: "5579107"
B0YBKR SEDOL: "B0YBKR5"
585284 SEDOL: "5852842"
B0YBKT SEDOL: "B0YBKT7"
B00030 SEDOL: "B000300"
</pre>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">class SEDOL(s: String) {
require(s.size == 6 || s.size == 7, "SEDOL length must be 6 or 7 characters")
require(s.size == 6 || s(6).asDigit == chksum, "Incorrect SEDOL checksum")
Line 3,268 ⟶ 3,832:
def chksum = 10 - ((s zip List(1, 3, 1, 7, 3, 9) map { case (c, w) => c.asDigit * w } sum) % 10)
override def toString = s.take(6) + chksum
}</langsyntaxhighlight>
 
Test cases:
Line 3,309 ⟶ 3,873:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func char: sedolCheckDigit (in string: sedol) is func
Line 3,343 ⟶ 3,907:
writeln(sedol <& sedolCheckDigit(sedol));
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 3,361 ⟶ 3,925:
 
=={{header|Sidef}}==
{{trans|Perl 6Raku}}
<langsyntaxhighlight lang="ruby">func sedol(s) {
 
die 'No vowels allowed' if (s ~~ /[AEIOU]/);
Line 3,390 ⟶ 3,954:
).each { |s|
say sedol(s);
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,408 ⟶ 3,972:
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
<langsyntaxhighlight lang="smalltalk">String extend [
includesAnyOf: aSet [
aSet do: [ :e | (self includes: e) ifTrue: [ ^true ] ].
^false
]
].</langsyntaxhighlight>
 
<langsyntaxhighlight lang="smalltalk">Object subclass: SEDOL [
|weight charList|
 
Line 3,457 ⟶ 4,021:
]
]
].</langsyntaxhighlight>
 
<langsyntaxhighlight lang="smalltalk">|sedol|
sedol := SEDOL new.
{ '710889'.
Line 3,470 ⟶ 4,034:
'B0YBKR'.
'585284'.
'B0YBKT' } do: [ :c | (sedol checked: c) displayNl ]</langsyntaxhighlight>
 
{{works with|Smalltalk/X}}
<syntaxhighlight lang="smalltalk">#(
'710889'
'B0YBKJ'
'406566'
'B0YBLH'
'228276'
'B0YBKL'
'557910'
'B0YBKR'
'585284'
'B0YBKT'
'B00030'
) do:[:in |
|um check|
 
sum := 0.
(in to:6) with:#[1 3 1 7 3 9 ] do:[:ch :weight |
sum := sum + (ch digitValue * weight).
].
check := (10 - (sum%10)) % 10.
Transcript showCR: ( in,(Character digitValue:check))
].</syntaxhighlight>
{{out}}
7108899
B0YBKJ7
4065663
B0YBLH2
2282765
B0YBKL9
5579107
B0YBKR5
5852842
B0YBKT7
B000300
 
=={{header|SQL PL}}==
{{works with|Db2 LUW}} version 9.7 or higher.
With SQL PL:
<langsyntaxhighlight lang="sql pl">
--#SET TERMINATOR @
 
Line 3,540 ⟶ 4,140:
RETURN TEXT || CHECK;
END @
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,588 ⟶ 4,188:
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">fun char2value c =
if List.exists (fn x => x = c) (explode "AEIOU") then raise Fail "no vowels"
else if Char.isDigit c then ord c - ord #"0"
Line 3,613 ⟶ 4,213:
"B0YBKR",
"585284",
"B0YBKT" ];</langsyntaxhighlight>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">namespace eval sedol {
variable chars {0 1 2 3 4 5 6 7 8 9 "" B C D "" F G H "" J K L M N "" P Q R S T "" V W X Y Z}
variable weight {1 3 1 7 3 9 1}
Line 3,653 ⟶ 4,253:
assert {$sedol eq $answer} "assertion failed: $sedol ne $answer"
puts $sedol
}</langsyntaxhighlight>
 
=={{header|Transact-SQL}}==
Line 3,659 ⟶ 4,259:
Returns empty string if invalid.
 
<langsyntaxhighlight lang="tsql">CREATE FUNCTION [dbo].[fn_CheckSEDOL]
( @SEDOL varchar(50) )
RETURNS varchar(7)
Line 3,721 ⟶ 4,321:
-- Return the result of the function
RETURN @SEDOL
END</langsyntaxhighlight>
 
Examples:
Line 3,749 ⟶ 4,349:
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT
check="1'3'1'7'3'9"
Line 3,770 ⟶ 4,370:
PRINT input, " checkdigit: ", checksum
ENDLOOP
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,794 ⟶ 4,394:
to the list of character values.
 
<langsyntaxhighlight Ursalalang="ursala">#import std
#import nat
 
Line 3,801 ⟶ 4,401:
charval = -:@rlXS num alphabet
iprod = sum:-0+ product*p/weights+ charval*
checksum = difference/10+ remainder\10+ iprod</langsyntaxhighlight>
 
An optimization following the J solution avoids a run-time subtraction
by complementing the coefficients at compile time using these
definitions in place of those above.
<langsyntaxhighlight Ursalalang="ursala">weights = difference/*10 <1,3,1,7,3,9>
checksum = remainder\10+ iprod</langsyntaxhighlight>
 
A further performance improvement subsumes the character value lookup
Line 3,813 ⟶ 4,413:
the version shown below.
 
<langsyntaxhighlight Ursalalang="ursala">lookup = -: (^/~& product^|/~& charval)*lsPrK0/weights alphabet
iprod = sum:-0+ lookup*p/weights</langsyntaxhighlight>
 
To optimize further, we can build a separate smaller multiplication table for
Line 3,821 ⟶ 4,421:
index directly into the input list.
 
<langsyntaxhighlight Ursalalang="ursala">lookups = (-:+ * ^/~&l product^|/charval ~&)* *-* -*weights alphabet
iprod = sum:-0+ gang +^|(~&,~)*lNrXXK9 ^(~&,&h!)* lookups</langsyntaxhighlight>
Here is a test program.
<langsyntaxhighlight Ursalalang="ursala">#show+
 
examples = ^T(~&,~&h+ %nP+ checksum)*t
Line 3,838 ⟶ 4,438:
B0YBKR
585284
B0YBKT]-</langsyntaxhighlight>
output:
<pre>7108899
Line 3,850 ⟶ 4,450:
5852842
B0YBKT7</pre>
 
=={{header|VBA}}==
<syntaxhighlight lang="lb">Function getSedolCheckDigit(Input1)
Dim mult(6) As Integer
mult(1) = 1: mult(2) = 3: mult(3) = 1
mult(4) = 7: mult(5) = 3: mult(6) = 9
If Len(Input1) <> 6 Then
getSedolCheckDigit = "Six chars only please"
Exit Function
End If
Input1 = UCase(Input1)
Total = 0
For i = 1 To 6
s1 = Mid(Input1, i, 1)
If (s1 = "A") Or (s1 = "E") Or (s1 = "I") Or (s1 = "O") Or (s1 = "U") Then
getSedolCheckDigit = "No vowels"
Exit Function
End If
If (Asc(s1) >= 48) And (Asc(s1) <= 57) Then
Total = Total + Val(s1) * mult(i)
Else
Total = Total + (Asc(s1) - 55) * mult(i)
End If
Next i
getSedolCheckDigit = Input1 + CStr((10 - (Total Mod 10)) Mod 10)
End Function</syntaxhighlight>
 
=={{header|VBScript}}==
Derived from the BASIC version.
<syntaxhighlight lang="vbscript">
<lang VBScript>
arr = Array("710889",_
"B0YBKJ",_
Line 3,897 ⟶ 4,525:
Next
getSEDOLCheckDigit = (10 - total Mod 10) Mod 10
End Function</langsyntaxhighlight>
 
{{out}}
Line 3,915 ⟶ 4,543:
 
=={{header|Visual FoxPro}}==
<langsyntaxhighlight lang="vfp">
#DEFINE ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#DEFINE VOWELS "AEIOU"
Line 3,989 ⟶ 4,617:
RETURN EMPTY(tcMsg)
ENDFUNC
</syntaxhighlight>
</lang>
{{out}}
<pre>
Output as in task description.
The last code is printed as BOO30A Vowels are not allowed.
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./str" for Char
import "./fmt" for Conv
 
var sedol = Fn.new { |s|
if (!(s is String && s.count == 6)) return false
var weights = [1, 3, 1, 7, 3, 9]
var sum = 0
for (i in 0..5) {
var c = s[i]
if (!Char.isUpper(c) && !Char.isDigit(c)) return null
if ("AEIOU".contains(c)) return null
sum = sum + Conv.atoi(c, 36) * weights[i]
}
var cd = (10 - sum%10) % 10
return s + "%(cd)"
}
 
var tests = [
"710889",
"B0YBKJ",
"406566",
"B0YBLH",
"228276",
"B0YBKL",
"557910",
"B0YBKR",
"585284",
"B0YBKT",
"B00030",
"I23456"
]
 
for (test in tests) {
var a
var ans = (a = sedol.call(test)) ? a : "not valid"
System.print("%(test) -> %(ans)")
}</syntaxhighlight>
 
{{out}}
<pre>
B0YBKJ -> B0YBKJ7
406566 -> 4065663
B0YBLH -> B0YBLH2
228276 -> 2282765
B0YBKL -> B0YBKL9
557910 -> 5579107
B0YBKR -> B0YBKR5
585284 -> 5852842
B0YBKT -> B0YBKT7
B00030 -> B000300
I23456 -> not valid
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">string 0; \use zero-terminated strings
 
func CheckDigit(Str); \Return the check digit for a SEDOL
char Str;
int Sum, I, C, V;
[Sum:= 0;
for I:= 0 to 6-1 do
[C:= Str(I);
case of
C>=^0 & C<=^9: V:= C-^0;
C>=^A & C<=^Z: V:= C-^A+10
other V:= -1;
case I of
1, 4: V:= V*3;
3: V:= V*7;
5: V:= V*9
other [];
Sum:= Sum+V;
];
return rem( (10 - rem(Sum/10)) / 10 ) + ^0;
];
 
int Sedol, N;
[Sedol:= ["710889",
"B0YBKJ",
"406566",
"B0YBLH",
"228276",
"B0YBKL",
"557910",
"B0YBKR",
"585284",
"B0YBKT",
"B00030"];
for N:= 0 to 11-1 do
[Text(0, Sedol(N));
ChOut(0, CheckDigit(Sedol(N)));
CrLf(0);
];
]</syntaxhighlight>
 
{{out}}
<pre>
7108899
B0YBKJ7
4065663
B0YBLH2
2282765
B0YBKL9
5579107
B0YBKR5
5852842
B0YBKT7
B000300
</pre>
 
=={{header|Yabasic}}==
<langsyntaxhighlight Yabasiclang="yabasic">data "710889", "B0YBKJ", "406566", "B0YBLH", "228276", "B0YBKL", "557910", "B0YBKR", "585284", "B0YBKT", "B00030", "AB", "B00A03", ""
 
do
Line 4,022 ⟶ 4,763:
NEXT
return d$ + CHR$(48 + mod(10 - mod(s, 10), 10))
end sub</langsyntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn checksum(text){
( text.len()!=6 or (text..matches("*[AEIOUaeioua-z]*")) ) and
throw(Exception.ValueError("Invalid SEDOL text: "+text));
Line 4,033 ⟶ 4,774:
else c.toAsc()-55;
}).zipWith('*,T(1,3,1,7,3,9)).sum() % 10) % 10;
}</langsyntaxhighlight>
It sure does look like that trailing %10 is extraneous. It also seems like lower case is implicitly invalid.
<langsyntaxhighlight lang="zkl">T("710889","B0YBKJ","406566","B0YBLH","228276",
"B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030")
.apply(checksum).println();</langsyntaxhighlight>
{{out}}
<pre>
885

edits