SEDOLs: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 46: | Line 46: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">F char2value(c) |
||
assert(c !C ‘AEIOU’, ‘No vowels’) |
assert(c !C ‘AEIOU’, ‘No vowels’) |
||
R Int(c, radix' 36) |
R Int(c, radix' 36) |
||
Line 69: | Line 69: | ||
L(sedol) sedols.split("\n") |
L(sedol) sedols.split("\n") |
||
print(sedol‘’checksum(sedol))</ |
print(sedol‘’checksum(sedol))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 86: | Line 86: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
< |
<syntaxhighlight lang="action!">INT FUNC SedolChecksum(CHAR ARRAY sedol) |
||
BYTE ARRAY weights=[1 3 1 7 3 9] |
BYTE ARRAY weights=[1 3 1 7 3 9] |
||
INT i,sum |
INT i,sum |
||
Line 144: | Line 144: | ||
Test("12345") |
Test("12345") |
||
Test("1234567") |
Test("1234567") |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/SEDOLs.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/SEDOLs.png Screenshot from Atari 8-bit computer] |
||
Line 165: | Line 165: | ||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |
||
< |
<syntaxhighlight lang="actionscript">//Return the code corresponding to a given character. |
||
//ActionScript does not have a character type, so 1-digit strings |
//ActionScript does not have a character type, so 1-digit strings |
||
//are used instead |
//are used instead |
||
Line 214: | Line 214: | ||
printWithCheck("585284"); |
printWithCheck("585284"); |
||
printWithCheck("B0YBKT"); |
printWithCheck("B0YBKT"); |
||
printWithCheck("B00030");</ |
printWithCheck("B00030");</syntaxhighlight> |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO; |
||
procedure Test_SEDOL is |
procedure Test_SEDOL is |
||
Line 256: | Line 256: | ||
Put_Line (Test (Index) & Character'Val (Character'Pos ('0') + Check (Test (Index)))); |
Put_Line (Test (Index) & Character'Val (Character'Pos ('0') + Check (Test (Index)))); |
||
end loop; |
end loop; |
||
end Test_SEDOL;</ |
end Test_SEDOL;</syntaxhighlight> |
||
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. |
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 274: | Line 274: | ||
{{trans|C}} |
{{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}} |
{{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}} |
||
< |
<syntaxhighlight lang="algol68">[]INT sedol weights = (1, 3, 1, 7, 3, 9); |
||
STRING reject = "AEIOUaeiou"; |
STRING reject = "AEIOUaeiou"; |
||
Line 331: | Line 331: | ||
OD; |
OD; |
||
done: SKIP |
done: SKIP |
||
)</ |
)</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>7108899 |
<pre>7108899 |
||
Line 345: | Line 345: | ||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
< |
<syntaxhighlight lang="algolw">begin |
||
% returns the check digit for the specified SEDOL % |
% returns the check digit for the specified SEDOL % |
||
string(1) procedure sedolCheckDigit ( string(6) value sedol ) ; |
string(1) procedure sedolCheckDigit ( string(6) value sedol ) ; |
||
Line 387: | Line 387: | ||
testCheckDigit( "B0YBKT", "7" ); |
testCheckDigit( "B0YBKT", "7" ); |
||
testCheckDigit( "B00030", "0" ) |
testCheckDigit( "B00030", "0" ) |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 405: | Line 405: | ||
=={{header|AppleScript}}== |
=={{header|AppleScript}}== |
||
< |
<syntaxhighlight lang="applescript">on appendCheckDigitToSEDOL(sedol) |
||
if ((count sedol) is not 6) then ¬ |
if ((count sedol) is not 6) then ¬ |
||
return {false, "Error in appendCheckDigitToSEDOL handler: " & sedol & " doesn't have 6 characters."} |
return {false, "Error in appendCheckDigitToSEDOL handler: " & sedol & " doesn't have 6 characters."} |
||
Line 447: | Line 447: | ||
set output to output as text |
set output to output as text |
||
set AppleScript's text item delimiters to astid |
set AppleScript's text item delimiters to astid |
||
return output</ |
return output</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
< |
<syntaxhighlight lang="applescript">"7108899 |
||
B0YBKJ7 |
B0YBKJ7 |
||
4065663 |
4065663 |
||
Line 460: | Line 460: | ||
5852842 |
5852842 |
||
B0YBKT7 |
B0YBKT7 |
||
B000300"</ |
B000300"</syntaxhighlight> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">ord0: to :integer `0` |
||
ord7: to :integer `7` |
ord7: to :integer `7` |
||
c2v: function [c][ |
c2v: function [c][ |
||
Line 488: | Line 488: | ||
loop sedols 'sed -> |
loop sedols 'sed -> |
||
print [sed "->" sed ++ checksum sed]</ |
print [sed "->" sed ++ checksum sed]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 508: | Line 508: | ||
===Full=== |
===Full=== |
||
< |
<syntaxhighlight lang="autohotkey">codes = 710889,B0YBKJ,406566,B0YBLH,228276,B0YBKL,557910,B0YBKR,585284,B0YBKT,B00030,ABCDEF,BBBBBBB |
||
Loop, Parse, codes, `, |
Loop, Parse, codes, `, |
||
output .= A_LoopField "`t-> " SEDOL(A_LoopField) "`n" |
output .= A_LoopField "`t-> " SEDOL(A_LoopField) "`n" |
||
Line 526: | Line 526: | ||
Return "Invalid character." |
Return "Invalid character." |
||
Return code . Mod(10-Mod(check_digit,10),10) |
Return code . Mod(10-Mod(check_digit,10),10) |
||
}</ |
}</syntaxhighlight> |
||
===Short=== |
===Short=== |
||
{{works with|AutoHotkey 1.1}} |
{{works with|AutoHotkey 1.1}} |
||
< |
<syntaxhighlight lang="autohotkey">MsgBox % SEDOL("710889") ;7108899 |
||
MsgBox % SEDOL("B0YBKJ") ;B0YBKJ7 |
MsgBox % SEDOL("B0YBKJ") ;B0YBKJ7 |
||
MsgBox % SEDOL("406566") ;4065663 |
MsgBox % SEDOL("406566") ;4065663 |
||
Line 546: | Line 546: | ||
s += ((c := Asc(A_LoopField)) >= 65 ? c - 65 + 10 : c - 48) * weights[A_Index] |
s += ((c := Asc(A_LoopField)) >= 65 ? c - 65 + 10 : c - 48) * weights[A_Index] |
||
return w Mod(10 - Mod(s, 10), 10) |
return w Mod(10 - Mod(s, 10), 10) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
Validate or calculate checksum of SEDOL codes read from standard input (one per line) |
Validate or calculate checksum of SEDOL codes read from standard input (one per line) |
||
< |
<syntaxhighlight lang="awk">function ord(a) |
||
{ |
{ |
||
return amap[a] |
return amap[a] |
||
Line 598: | Line 598: | ||
print sedol sedolcheck |
print sedol sedolcheck |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
{{works with|QBasic|1.1}} |
{{works with|QBasic|1.1}} |
||
{{works with|QuickBasic|4.5}} |
{{works with|QuickBasic|4.5}} |
||
< |
<syntaxhighlight lang="qbasic">DECLARE FUNCTION getSedolCheckDigit! (str AS STRING) |
||
DO |
DO |
||
INPUT a$ |
INPUT a$ |
||
Line 633: | Line 633: | ||
NEXT i |
NEXT i |
||
getSedolCheckDigit = (10 - (total MOD 10)) MOD 10 |
getSedolCheckDigit = (10 - (total MOD 10)) MOD 10 |
||
END FUNCTION</ |
END FUNCTION</syntaxhighlight> |
||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
< |
<syntaxhighlight lang="bbcbasic"> PRINT FNsedol("710889") |
||
PRINT FNsedol("B0YBKJ") |
PRINT FNsedol("B0YBKJ") |
||
PRINT FNsedol("406566") |
PRINT FNsedol("406566") |
||
Line 656: | Line 656: | ||
s% += (a% + 7 * (a% > 9)) * weights%(i%) |
s% += (a% + 7 * (a% > 9)) * weights%(i%) |
||
NEXT |
NEXT |
||
= d$ + CHR$(&30 + (10 - s% MOD 10) MOD 10)</ |
= d$ + CHR$(&30 + (10 - s% MOD 10) MOD 10)</syntaxhighlight> |
||
'''Output:''' |
'''Output:''' |
||
<pre> |
<pre> |
||
Line 675: | Line 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). |
'''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). |
||
< |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <ctype.h> |
#include <ctype.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 722: | Line 722: | ||
} |
} |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
Fed the input list from the task description, the output is: |
Fed the input list from the task description, the output is: |
||
Line 738: | Line 738: | ||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |
||
< |
<syntaxhighlight lang="csharp">static int[] sedol_weights = { 1, 3, 1, 7, 3, 9 }; |
||
static int sedolChecksum(string sedol) |
static int sedolChecksum(string sedol) |
||
{ |
{ |
||
Line 764: | Line 764: | ||
return (10 - (sum % 10)) % 10; |
return (10 - (sum % 10)) % 10; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|C++}}== |
=={{header|C++}}== |
||
< |
<syntaxhighlight lang="cpp"> |
||
#include <numeric> |
#include <numeric> |
||
#include <cctype> |
#include <cctype> |
||
Line 811: | Line 811: | ||
return 0; |
return 0; |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Caché ObjectScript}}== |
=={{header|Caché ObjectScript}}== |
||
< |
<syntaxhighlight lang="cos">Class Utils.Check [ Abstract ] |
||
{ |
{ |
||
Line 833: | Line 833: | ||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out|Examples}} |
{{out|Examples}} |
||
<pre>USER>For { Read s Quit:s="" Write ": "_##class(Utils.Check).SEDOL(s), ! } |
<pre>USER>For { Read s Quit:s="" Write ": "_##class(Utils.Check).SEDOL(s), ! } |
||
Line 851: | Line 851: | ||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
< |
<syntaxhighlight lang="clojure">(defn sedols [xs] |
||
(letfn [(sedol [ys] (let [weights [1 3 1 7 3 9] |
(letfn [(sedol [ys] (let [weights [1 3 1 7 3 9] |
||
convtonum (map #(Character/getNumericValue %) ys) |
convtonum (map #(Character/getNumericValue %) ys) |
||
check (-> (reduce + (map * weights convtonum)) (rem 10) (->> (- 10)) (rem 10))] |
check (-> (reduce + (map * weights convtonum)) (rem 10) (->> (- 10)) (rem 10))] |
||
(str ys check)))] |
(str ys check)))] |
||
(map #(sedol %) xs)))</ |
(map #(sedol %) xs)))</syntaxhighlight> |
||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
{{works with|GNU Cobol|2.0}} |
{{works with|GNU Cobol|2.0}} |
||
< |
<syntaxhighlight lang="cobol"> >>SOURCE FREE |
||
IDENTIFICATION DIVISION. |
IDENTIFICATION DIVISION. |
||
PROGRAM-ID. sedol. |
PROGRAM-ID. sedol. |
||
Line 938: | Line 938: | ||
CLOSE sedol-file |
CLOSE sedol-file |
||
. |
. |
||
END PROGRAM sedol.</ |
END PROGRAM sedol.</syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Implemented from scratch using the description on Wikipedia as specification. |
Implemented from scratch using the description on Wikipedia as specification. |
||
{{Works with|ClozureCL}} |
{{Works with|ClozureCL}} |
||
< |
<syntaxhighlight lang="lisp">(defun append-sedol-check-digit (sedol &key (start 0) (end (+ start 6))) |
||
(assert (<= 0 start end (length sedol))) |
(assert (<= 0 start end (length sedol))) |
||
(assert (= (- end start) 6)) |
(assert (= (- end start) 6)) |
||
Line 954: | Line 954: | ||
(head (subseq sedol start end)) |
(head (subseq sedol start end)) |
||
(tail (digit-char posn))) |
(tail (digit-char posn))) |
||
(return (concatenate 'string head (list tail))))))</ |
(return (concatenate 'string head (list tail))))))</syntaxhighlight> |
||
=={{header|D}}== |
=={{header|D}}== |
||
===Functional Version=== |
===Functional Version=== |
||
< |
<syntaxhighlight lang="d">import std.stdio, std.algorithm, std.string, std.numeric, std.ascii; |
||
char checksum(in char[] sedol) pure @safe /*@nogc*/ |
char checksum(in char[] sedol) pure @safe /*@nogc*/ |
||
Line 977: | Line 977: | ||
B0YBKL 557910 B0YBKR 585284 B0YBKT".split) |
B0YBKL 557910 B0YBKR 585284 B0YBKT".split) |
||
writeln(sedol, sedol.checksum); |
writeln(sedol, sedol.checksum); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>7108899 |
<pre>7108899 |
||
Line 992: | Line 992: | ||
===Imperative Version=== |
===Imperative Version=== |
||
Longer, faster lower-level version, same output. |
Longer, faster lower-level version, same output. |
||
< |
<syntaxhighlight lang="d">import std.stdio, std.algorithm, std.string, std.numeric, std.ascii; |
||
char sedolChecksum(in char[] sedol) pure nothrow @safe /*@nogc*/ |
char sedolChecksum(in char[] sedol) pure nothrow @safe /*@nogc*/ |
||
Line 1,029: | Line 1,029: | ||
"585284", "B0YBKT"]) |
"585284", "B0YBKT"]) |
||
writeln(s, s.sedolChecksum); |
writeln(s, s.sedolChecksum); |
||
}</ |
}</syntaxhighlight> |
||
===Short Version=== |
===Short Version=== |
||
Same output. |
Same output. |
||
< |
<syntaxhighlight lang="d">void main() { |
||
import std.stdio, std.algorithm, std.string, std.numeric,std.ascii; |
import std.stdio, std.algorithm, std.string, std.numeric,std.ascii; |
||
Line 1,041: | Line 1,041: | ||
.map!(c => c.isDigit ? c - '0' : c - 'A' + 10) |
.map!(c => c.isDigit ? c - '0' : c - 'A' + 10) |
||
.dotProduct([1, 3, 1, 7, 3, 9]) % 10); |
.dotProduct([1, 3, 1, 7, 3, 9]) % 10); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
< |
<syntaxhighlight lang="delphi">program Sedol; |
||
{$APPTYPE CONSOLE} |
{$APPTYPE CONSOLE} |
||
Line 1,124: | Line 1,124: | ||
readln; |
readln; |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
Line 1,140: | Line 1,140: | ||
=={{header|E}}== |
=={{header|E}}== |
||
< |
<syntaxhighlight lang="e">def weights := [1,3,1,7,3,9] |
||
def Digit := ('0'..'9') |
def Digit := ('0'..'9') |
||
def Letter := ('B'..'D'|'F'..'H'|'J'..'N'|'P'..'T'|'V'..'Z') |
def Letter := ('B'..'D'|'F'..'H'|'J'..'N'|'P'..'T'|'V'..'Z') |
||
Line 1,176: | Line 1,176: | ||
B0YBKT".trim().split("\n") { |
B0YBKT".trim().split("\n") { |
||
println(addChecksum(sedol.trim())) |
println(addChecksum(sedol.trim())) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Elixir}}== |
=={{header|Elixir}}== |
||
{{trans|Ruby}} |
{{trans|Ruby}} |
||
< |
<syntaxhighlight lang="elixir">defmodule SEDOL do |
||
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints |
@sedol_char "0123456789BCDFGHJKLMNPQRSTVWXYZ" |> String.codepoints |
||
@sedolweight [1,3,1,7,3,9] |
@sedolweight [1,3,1,7,3,9] |
||
Line 1,222: | Line 1,222: | ||
e in ArgumentError -> IO.inspect e |
e in ArgumentError -> IO.inspect e |
||
end |
end |
||
end)</ |
end)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,251: | Line 1,251: | ||
{{Works with|Office 365 Betas 2021}} |
{{Works with|Office 365 Betas 2021}} |
||
< |
<syntaxhighlight lang="lisp">SEDOLCHECKSUM |
||
=LAMBDA(s, |
=LAMBDA(s, |
||
IF(6 = LEN(s), |
IF(6 = LEN(s), |
||
Line 1,283: | Line 1,283: | ||
"Expected a 6-character SEDOL" |
"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: |
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(x, |
||
LAMBDA(xs, |
LAMBDA(xs, |
||
Line 1,296: | Line 1,296: | ||
MUL |
MUL |
||
=LAMBDA(a, LAMBDA(b, a * b))</ |
=LAMBDA(a, LAMBDA(b, a * b))</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
Line 1,392: | Line 1,392: | ||
=={{header|F Sharp|F#}}== |
=={{header|F Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp">open System |
||
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL" |
let Inputs = ["710889"; "B0YBKJ"; "406566"; "B0YBLH"; "228276"; "B0YBKL" |
||
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"] |
"557910"; "B0YBKR"; "585284"; "B0YBKT"; "B00030"] |
||
Line 1,419: | Line 1,419: | ||
addCheckDigit Inputs |> List.iter (printfn "%s") |
addCheckDigit Inputs |> List.iter (printfn "%s") |
||
with |
with |
||
ex -> printfn "ERROR: %s" ex.Message</ |
ex -> printfn "ERROR: %s" ex.Message</syntaxhighlight> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: combinators combinators.short-circuit formatting io kernel |
||
math math.parser regexp sequences unicode ; |
math math.parser regexp sequences unicode ; |
||
IN: rosetta-code.sedols |
IN: rosetta-code.sedols |
||
Line 1,463: | Line 1,463: | ||
input [ dup sedol-check-digit "%-6s %s\n" printf ] each ; |
input [ dup sedol-check-digit "%-6s %s\n" printf ] each ; |
||
MAIN: sedol-demo</ |
MAIN: sedol-demo</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,486: | Line 1,486: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
< |
<syntaxhighlight lang="forth">create weight 1 , 3 , 1 , 7 , 3 , 9 , |
||
: char>num ( '0-9A-Z' -- 0..35 ) |
: char>num ( '0-9A-Z' -- 0..35 ) |
||
Line 1,513: | Line 1,513: | ||
sedol" B0YBKR" B0YBKR5 ok |
sedol" B0YBKR" B0YBKR5 ok |
||
sedol" 585284" 5852842 ok |
sedol" 585284" 5852842 ok |
||
sedol" B0YBKT" B0YBKT7 ok</ |
sedol" B0YBKT" B0YBKT7 ok</syntaxhighlight> |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
{{Works with|Fortran|90 and later}} |
{{Works with|Fortran|90 and later}} |
||
< |
<syntaxhighlight lang="fortran">MODULE SEDOL_CHECK |
||
IMPLICIT NONE |
IMPLICIT NONE |
||
CONTAINS |
CONTAINS |
||
Line 1,559: | Line 1,559: | ||
END DO |
END DO |
||
END PROGRAM SEDOLTEST</ |
END PROGRAM SEDOLTEST</syntaxhighlight> |
||
Output |
Output |
||
710889 7108899 |
710889 7108899 |
||
Line 1,573: | Line 1,573: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic">' version 05-07-2015 |
||
' compile with: fbc -s console |
' compile with: fbc -s console |
||
Line 1,665: | Line 1,665: | ||
Print : Print "hit any key to end program" |
Print : Print "hit any key to end program" |
||
Sleep |
Sleep |
||
End</ |
End</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Calculated checksum |
<pre>Calculated checksum |
||
Line 1,703: | Line 1,703: | ||
=={{header|Gambas}}== |
=={{header|Gambas}}== |
||
'''[https://gambas-playground.proko.eu/?gist=905f91c785f1f15a360726717731862f Click this link to run this code]''' |
'''[https://gambas-playground.proko.eu/?gist=905f91c785f1f15a360726717731862f Click this link to run this code]''' |
||
< |
<syntaxhighlight lang="gambas">Public Sub Main() |
||
Dim byWeight As Byte[] = [1, 3, 1, 7, 3, 9, 1] |
Dim byWeight As Byte[] = [1, 3, 1, 7, 3, 9, 1] |
||
Dim byCount, byCompute As Byte |
Dim byCount, byCompute As Byte |
||
Line 1,731: | Line 1,731: | ||
Next |
Next |
||
End</ |
End</syntaxhighlight> |
||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 1,748: | Line 1,748: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
<syntaxhighlight lang="go"> |
|||
<lang go> |
|||
package main |
package main |
||
Line 1,811: | Line 1,811: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 1,839: | Line 1,839: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
< |
<syntaxhighlight lang="groovy">def checksum(text) { |
||
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text" |
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text" |
||
Line 1,848: | Line 1,848: | ||
text + (10 - (sum % 10)) % 10 |
text + (10 - (sum % 10)) % 10 |
||
} |
} |
||
String.metaClass.sedol = { this.&checksum(delegate) }</ |
String.metaClass.sedol = { this.&checksum(delegate) }</syntaxhighlight> |
||
Test Code: |
Test Code: |
||
< |
<syntaxhighlight lang="groovy">[ '710889': '7108899', 'B0YBKJ': 'B0YBKJ7', '406566': '4065663', 'B0YBLH': 'B0YBLH2', |
||
'228276': '2282765', 'B0YBKL': 'B0YBKL9', '557910': '5579107', 'B0YBKR': 'B0YBKR5', |
'228276': '2282765', 'B0YBKL': 'B0YBKL9', '557910': '5579107', 'B0YBKR': 'B0YBKR5', |
||
'585284': '5852842', 'B0YBKT': 'B0YBKT7', 'B00030': 'B000300'].each { text, expected -> |
'585284': '5852842', 'B0YBKT': 'B0YBKT7', 'B00030': 'B000300'].each { text, expected -> |
||
println "Checking $text -> $expected" |
println "Checking $text -> $expected" |
||
assert expected == text.sedol() |
assert expected == text.sedol() |
||
}</ |
}</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>Checking 710889 -> 7108899 |
<pre>Checking 710889 -> 7108899 |
||
Line 1,870: | Line 1,870: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import Data.Char (isAsciiUpper, isDigit, ord) |
||
-------------------------- SEDOLS ------------------------ |
-------------------------- SEDOLS ------------------------ |
||
Line 1,918: | Line 1,918: | ||
"BOYBKT", -- Ill formed test case - illegal vowel. |
"BOYBKT", -- Ill formed test case - illegal vowel. |
||
"B00030" |
"B00030" |
||
]</ |
]</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>7108899 |
<pre>7108899 |
||
Line 1,934: | Line 1,934: | ||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
< |
<syntaxhighlight lang="icon">procedure main() |
||
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"| |
every write(sedol("710889"|"B0YBKJ"|"406566"|"B0YBLH"|"228276"| |
||
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030")) |
"B0YBKL"|"557910"|"B0YBKR"|"585284"|"B0YBKT"|"B00030")) |
||
Line 1,952: | Line 1,952: | ||
return x || (10 - (t%10)) % 10 # complete |
return x || (10 - (t%10)) % 10 # complete |
||
} |
} |
||
end</ |
end</syntaxhighlight> |
||
=={{header|J}}== |
=={{header|J}}== |
||
There are several ways to perform this in J. This most closely follows the algorithmic description at Wikipedia: |
There are several ways to perform this in J. This most closely follows the algorithmic description at Wikipedia: |
||
< |
<syntaxhighlight lang="j">sn =. '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
||
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)</ |
ac0 =: (, 10 | 1 3 1 7 3 9 +/@:* -)&.(sn i. |:)</syntaxhighlight> |
||
However, because J is so concise, having written the above, it becomes clear that the negation (<tt>-</tt>) is unnecessary. |
However, because J is so concise, having written the above, it becomes clear that the negation (<tt>-</tt>) is unnecessary. |
||
Line 1,963: | Line 1,963: | ||
Which leads us to this more efficient formulation: |
Which leads us to this more efficient formulation: |
||
< |
<syntaxhighlight lang="j">ac1 =: (, 10 | (10 - 1 3 1 7 3 9) +/@:* ])&.(sn i. |:)</syntaxhighlight> |
||
which reduces to: |
which reduces to: |
||
< |
<syntaxhighlight lang="j">ac2 =: (, 10 | 9 7 9 3 7 1 +/@:* ])&.(sn i. |:)</syntaxhighlight> |
||
Which is just as concise as <tt>ac0</tt>, but faster. |
Which is just as concise as <tt>ac0</tt>, but faster. |
||
Line 1,971: | Line 1,971: | ||
Which leads us to: |
Which leads us to: |
||
< |
<syntaxhighlight lang="j">ac3 =: (,"1 0 (841 $ '0987654321') {~ 1 3 1 7 3 9 +/ .*~ sn i. ])</syntaxhighlight> |
||
Which is more than twice as fast as even the optimized formulation (<tt>ac2</tt>), though it is slightly longer. |
Which is more than twice as fast as even the optimized formulation (<tt>ac2</tt>), though it is slightly longer. |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">import java.util.Scanner; |
||
public class SEDOL{ |
public class SEDOL{ |
||
Line 2,005: | Line 2,005: | ||
return (str.length() == 6) && !str.toUpperCase().matches(".*?[AEIOU].*?"); |
return (str.length() == 6) && !str.toUpperCase().matches(".*?[AEIOU].*?"); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
===Imperative=== |
===Imperative=== |
||
< |
<syntaxhighlight lang="javascript">function sedol(input) { |
||
return input + sedol_check_digit(input); |
return input + sedol_check_digit(input); |
||
} |
} |
||
Line 2,049: | Line 2,049: | ||
print("error: " + e); |
print("error: " + e); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
output |
output |
||
<pre>7108899 |
<pre>7108899 |
||
Line 2,067: | Line 2,067: | ||
===Functional=== |
===Functional=== |
||
< |
<syntaxhighlight lang="javascript">(() => { |
||
'use strict'; |
'use strict'; |
||
Line 2,230: | Line 2,230: | ||
// MAIN --- |
// MAIN --- |
||
return main(); |
return main(); |
||
})();</ |
})();</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>7108899 |
<pre>7108899 |
||
Line 2,247: | Line 2,247: | ||
{{works with|jq|1.4}} |
{{works with|jq|1.4}} |
||
This implementation accepts strings with lowercase letters, but converts them to uppercase. |
This implementation accepts strings with lowercase letters, but converts them to uppercase. |
||
< |
<syntaxhighlight lang="jq">def ascii_upcase: |
||
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode; |
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode; |
||
Line 2,289: | Line 2,289: | ||
else $ans |
else $ans |
||
end ; |
end ; |
||
sedolize</ |
sedolize</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
# Assuming sedol.txt contains the input in the task description |
# Assuming sedol.txt contains the input in the task description |
||
Line 2,298: | Line 2,298: | ||
{{works with|Julia|0.6}} |
{{works with|Julia|0.6}} |
||
< |
<syntaxhighlight lang="julia">using Base.Test |
||
function appendchecksum(chars::AbstractString) |
function appendchecksum(chars::AbstractString) |
||
Line 2,318: | Line 2,318: | ||
@test appendchecksum(t) == c |
@test appendchecksum(t) == c |
||
end |
end |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,325: | Line 2,325: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">// version 1.1.0 |
||
val weights = listOf(1, 3, 1, 7, 3, 9, 1) |
val weights = listOf(1, 3, 1, 7, 3, 9, 1) |
||
Line 2,349: | Line 2,349: | ||
"557910", "B0YBKR", "585284", "B0YBKT", "B00030") |
"557910", "B0YBKR", "585284", "B0YBKT", "B00030") |
||
for (sedol6 in sedol6s) println("$sedol6 -> ${sedol7(sedol6)}") |
for (sedol6 in sedol6s) println("$sedol6 -> ${sedol7(sedol6)}") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,369: | Line 2,369: | ||
{{trans|Go}} |
{{trans|Go}} |
||
{{works with|langur|0.8.10}} |
{{works with|langur|0.8.10}} |
||
< |
<syntaxhighlight lang="langur">val .csd = f(.code) { |
||
given len(.code) { |
given len(.code) { |
||
case 0: |
case 0: |
||
Line 2,426: | Line 2,426: | ||
$" (SEDOL test failed; expected check digit \.expect;)"} |
$" (SEDOL test failed; expected check digit \.expect;)"} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,451: | Line 2,451: | ||
=={{header|Liberty BASIC}}== |
=={{header|Liberty BASIC}}== |
||
<syntaxhighlight lang="lb"> |
|||
<lang lb> |
|||
'adapted from BASIC solution |
'adapted from BASIC solution |
||
mult(1) = 1: mult(2) = 3: mult(3) = 1 |
mult(1) = 1: mult(2) = 3: mult(3) = 1 |
||
Line 2,483: | Line 2,483: | ||
getSedolCheckDigit = (10 - (total MOD 10)) MOD 10 |
getSedolCheckDigit = (10 - (total MOD 10)) MOD 10 |
||
END FUNCTION |
END FUNCTION |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|M4}}== |
=={{header|M4}}== |
||
< |
<syntaxhighlight lang="m4">divert(-1) |
||
changequote(`[',`]') |
changequote(`[',`]') |
||
define([_bar],include(sedol.inp)) |
define([_bar],include(sedol.inp)) |
||
Line 2,502: | Line 2,502: | ||
]) |
]) |
||
divert |
divert |
||
eachline(_bar,[checksum])</ |
eachline(_bar,[checksum])</syntaxhighlight> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">SEDOL[Code_?(Function[v,StringFreeQ[v,{"A","E","I","O","U"}]])]:= |
||
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code] |
Code<>ToString[10-Mod[ToExpression[Quiet[Flatten[Characters[Code] |
||
/.x_?LetterQ->(ToCharacterCode[x]-55)]]].{1,3,1,7,3,9},10]] |
/.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"}]</ |
Scan[Print[SEDOL[#]] &, {"710889","B0YBKJ","406566","B0YBLH","228276","B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030","DUMMY"}]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,525: | Line 2,525: | ||
=={{header|Mercury}}== |
=={{header|Mercury}}== |
||
<lang>:- module sedol. |
<syntaxhighlight lang="text">:- module sedol. |
||
:- interface. |
:- interface. |
||
Line 2,577: | Line 2,577: | ||
is_vowel('I'). |
is_vowel('I'). |
||
is_vowel('O'). |
is_vowel('O'). |
||
is_vowel('U').</ |
is_vowel('U').</syntaxhighlight> |
||
=={{header|Modula-3}}== |
=={{header|Modula-3}}== |
||
< |
<syntaxhighlight lang="modula3">MODULE SEDOL EXPORTS Main; |
||
IMPORT IO, Fmt, Text, Stdio; |
IMPORT IO, Fmt, Text, Stdio; |
||
Line 2,623: | Line 2,623: | ||
| BadSedol(text) => IO.Put(text & "\n", Stdio.stderr); |
| BadSedol(text) => IO.Put(text & "\n", Stdio.stderr); |
||
END; |
END; |
||
END SEDOL.</ |
END SEDOL.</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>7108899 |
<pre>7108899 |
||
Line 2,637: | Line 2,637: | ||
=={{header|MUMPS}}== |
=={{header|MUMPS}}== |
||
< |
<syntaxhighlight lang="mumps">SEDOL |
||
NEW A,B |
NEW A,B |
||
SEDOL1 |
SEDOL1 |
||
Line 2,657: | Line 2,657: | ||
NEW UP,LO |
NEW UP,LO |
||
SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ",LO="abcdefghijklmnopqrstuvwxyz" |
SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ",LO="abcdefghijklmnopqrstuvwxyz" |
||
QUIT $TRANSLATE(X,LO,UP)</ |
QUIT $TRANSLATE(X,LO,UP)</syntaxhighlight> |
||
Examples: |
Examples: |
||
<pre>USER>D SEDOL^ROSETTA |
<pre>USER>D SEDOL^ROSETTA |
||
Line 2,689: | Line 2,689: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">proc c2v(c: char): int = |
||
assert c notin "AEIOU" |
assert c notin "AEIOU" |
||
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7') |
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7') |
||
Line 2,704: | Line 2,704: | ||
"228276", "B0YBKL", "557910", "B0YBKR", |
"228276", "B0YBKL", "557910", "B0YBKR", |
||
"585284", "B0YBKT", "B00030"]: |
"585284", "B0YBKT", "B00030"]: |
||
echo sedol, " → ", sedol & checksum(sedol)</ |
echo sedol, " → ", sedol & checksum(sedol)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,720: | Line 2,720: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
< |
<syntaxhighlight lang="ocaml">let char2value c = |
||
assert (not (String.contains "AEIOU" c)); |
assert (not (String.contains "AEIOU" c)); |
||
match c with |
match c with |
||
Line 2,747: | Line 2,747: | ||
"B0YBKR"; |
"B0YBKR"; |
||
"585284"; |
"585284"; |
||
"B0YBKT" ]</ |
"B0YBKT" ]</syntaxhighlight> |
||
=={{header|Oforth}}== |
=={{header|Oforth}}== |
||
< |
<syntaxhighlight lang="oforth">func: sedol(s) |
||
[ 1, 3, 1, 7, 3, 9 ] s |
[ 1, 3, 1, 7, 3, 9 ] s |
||
zipWith(#[ dup isDigit ifTrue: [ '0' - ] else: [ 'A' - 10 + ] * ]) sum |
zipWith(#[ dup isDigit ifTrue: [ '0' - ] else: [ 'A' - 10 + ] * ]) sum |
||
10 mod 10 swap - 10 mod |
10 mod 10 swap - 10 mod |
||
StringBuffer new s << swap '0' + <<c ;</ |
StringBuffer new s << swap '0' + <<c ;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,776: | Line 2,776: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{works with|Free_Pascal}} |
{{works with|Free_Pascal}} |
||
< |
<syntaxhighlight lang="pascal">program Sedols(output); |
||
function index(c: char): integer; |
function index(c: char): integer; |
||
Line 2,820: | Line 2,820: | ||
writeln(codes[i], ' -> ', seforl); |
writeln(codes[i], ' -> ', seforl); |
||
end; |
end; |
||
end.</ |
end.</syntaxhighlight> |
||
Output: |
Output: |
||
<pre>% ./Sedols |
<pre>% ./Sedols |
||
Line 2,837: | Line 2,837: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
This program reads from standard input. |
This program reads from standard input. |
||
< |
<syntaxhighlight lang="perl">use List::Util qw(sum); |
||
use POSIX qw(strtol); |
use POSIX qw(strtol); |
||
Line 2,862: | Line 2,862: | ||
chomp; |
chomp; |
||
print sedol($_), "\n"; |
print sedol($_), "\n"; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<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> |
<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> |
||
<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> |
<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> |
||
Line 2,898: | Line 2,898: | ||
<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> |
<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> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 2,915: | Line 2,915: | ||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
< |
<syntaxhighlight lang="php">function char2value($c) { |
||
assert(stripos('AEIOU', $c) === FALSE); |
assert(stripos('AEIOU', $c) === FALSE); |
||
return intval($c, 36); |
return intval($c, 36); |
||
Line 2,940: | Line 2,940: | ||
'585284', |
'585284', |
||
'B0YBKT') as $sedol) |
'B0YBKT') as $sedol) |
||
echo $sedol, checksum($sedol), "\n";</ |
echo $sedol, checksum($sedol), "\n";</syntaxhighlight> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
< |
<syntaxhighlight lang="picolisp">(de sedol (Str) |
||
(pack Str |
(pack Str |
||
(char |
(char |
||
Line 2,963: | Line 2,963: | ||
(for S '("710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL" "557910" "B0YBKR" "585284" "B0YBKT" "B00030") |
(for S '("710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL" "557910" "B0YBKR" "585284" "B0YBKT" "B00030") |
||
(prinl (sedol S)) )</ |
(prinl (sedol S)) )</syntaxhighlight> |
||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
< |
<syntaxhighlight lang="pli">/* Compute SEDOLs; includes check for invalid characters. */ |
||
sedol: procedure options (main); /* 3 March 2012 */ |
sedol: procedure options (main); /* 3 March 2012 */ |
||
declare alphabet character (36) static initial |
declare alphabet character (36) static initial |
||
Line 2,988: | Line 2,988: | ||
put edit (s, v) (x(2), a, f(1)); put edit (' ') (a); |
put edit (s, v) (x(2), a, f(1)); put edit (' ') (a); |
||
end; |
end; |
||
end sedol;</ |
end sedol;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,007: | Line 3,007: | ||
=={{header|Potion}}== |
=={{header|Potion}}== |
||
No extra credit. |
No extra credit. |
||
< |
<syntaxhighlight lang="potion">sedolnum = (c) : |
||
if ("0" ord <= c ord and c ord <= "9" ord): c number integer. |
if ("0" ord <= c ord and c ord <= "9" ord): c number integer. |
||
else: 10 + c ord - "A" ord. |
else: 10 + c ord - "A" ord. |
||
Line 3,019: | Line 3,019: | ||
. |
. |
||
(str, (10 - (sum % 10)) % 10) join |
(str, (10 - (sum % 10)) % 10) join |
||
.</ |
.</syntaxhighlight> |
||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
< |
<syntaxhighlight lang="powershell">function Add-SEDOLCheckDigit |
||
{ |
{ |
||
Param ( # Validate input as six-digit SEDOL number |
Param ( # Validate input as six-digit SEDOL number |
||
Line 3,069: | Line 3,069: | ||
{ |
{ |
||
Add-SEDOLCheckDigit -SixDigitSEDOL $PartialSEDOL |
Add-SEDOLCheckDigit -SixDigitSEDOL $PartialSEDOL |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>7108899 |
<pre>7108899 |
||
Line 3,084: | Line 3,084: | ||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
< |
<syntaxhighlight lang="purebasic">Procedure.s SEDOLs(rawstring$) |
||
Protected i, j, sum, c, m |
Protected i, j, sum, c, m |
||
For i=1 To Len(rawstring$) |
For i=1 To Len(rawstring$) |
||
Line 3,123: | Line 3,123: | ||
Data.s "710889","B0YBKJ","406566","B0YBLH","228276" |
Data.s "710889","B0YBKJ","406566","B0YBLH","228276" |
||
Data.s "B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030" |
Data.s "B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030" |
||
EndDataSection</ |
EndDataSection</syntaxhighlight> |
||
[[Image:PB SEDOL.png]] |
[[Image:PB SEDOL.png]] |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">def char2value(c): |
||
assert c not in 'AEIOU', "No vowels" |
assert c not in 'AEIOU', "No vowels" |
||
return int(c, 36) |
return int(c, 36) |
||
Line 3,152: | Line 3,152: | ||
B0YBKT |
B0YBKT |
||
'''.split(): |
'''.split(): |
||
print sedol + checksum(sedol)</ |
print sedol + checksum(sedol)</syntaxhighlight> |
||
Line 3,158: | Line 3,158: | ||
{{Works with|Python|3.7}} |
{{Works with|Python|3.7}} |
||
< |
<syntaxhighlight lang="python">'''SEDOL checksum digits''' |
||
from functools import reduce |
from functools import reduce |
||
Line 3,282: | Line 3,282: | ||
# MAIN --- |
# MAIN --- |
||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main()</ |
main()</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>SEDOL checksum digits: |
<pre>SEDOL checksum digits: |
||
Line 3,300: | Line 3,300: | ||
=={{header|Q}}== |
=={{header|Q}}== |
||
< |
<syntaxhighlight lang="q">scd:{ |
||
v:{("i"$x) - ?[("0"<=x) & x<="9"; "i"$"0"; -10+"i"$"A"]} each x; / Turn characters of SEDOL into their values |
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 |
w:sum v*1 3 1 7 3 9; / Weighted sum of values |
||
Line 3,307: | Line 3,307: | ||
} |
} |
||
scd each ("710889";"B0YBKJ";"406566";"B0YBLH";"228276";"B0YBKL";"557910";"B0YBKR";"585284";"B0YBKT";"B00030")</ |
scd each ("710889";"B0YBKJ";"406566";"B0YBLH";"228276";"B0YBKL";"557910";"B0YBKR";"585284";"B0YBKT";"B00030")</syntaxhighlight> |
||
=={{header|R}}== |
=={{header|R}}== |
||
< |
<syntaxhighlight lang="rsplus"># Read in data from text connection |
||
datalines <- readLines(tc <- textConnection("710889 |
datalines <- readLines(tc <- textConnection("710889 |
||
B0YBKJ |
B0YBKJ |
||
Line 3,346: | Line 3,346: | ||
#Print in format requested |
#Print in format requested |
||
writeLines(withchkdig)</ |
writeLines(withchkdig)</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
;;; Since the Task gives us unchecksummed and checksummed SEDOLs, and |
;;; Since the Task gives us unchecksummed and checksummed SEDOLs, and |
||
;;; we'll just take a list of the output SEDOLs and remove their last |
;;; we'll just take a list of the output SEDOLs and remove their last |
||
Line 3,411: | Line 3,411: | ||
(check-false (invalid-SEDOL? S)) |
(check-false (invalid-SEDOL? S)) |
||
(check-equal? (SEDOL-append-checksum (substring S 0 6)) |
(check-equal? (SEDOL-append-checksum (substring S 0 6)) |
||
S (format "test SEDOL for ~a" S))))</ |
S (format "test SEDOL for ~a" S))))</syntaxhighlight> |
||
Output: |
Output: |
||
Line 3,434: | Line 3,434: | ||
{{trans|Perl}} |
{{trans|Perl}} |
||
{{Works with|rakudo|2015-12-17}} |
{{Works with|rakudo|2015-12-17}} |
||
<lang |
<syntaxhighlight lang="raku" line>sub sedol( Str $s ) { |
||
die 'No vowels allowed' if $s ~~ /<[AEIOU]>/; |
die 'No vowels allowed' if $s ~~ /<[AEIOU]>/; |
||
die 'Invalid format' if $s !~~ /^ <[0..9B..DF..HJ..NP..TV..Z]>**6 $ /; |
die 'Invalid format' if $s !~~ /^ <[0..9B..DF..HJ..NP..TV..Z]>**6 $ /; |
||
Line 3,459: | Line 3,459: | ||
B0YBKT |
B0YBKT |
||
B00030 |
B00030 |
||
>;</ |
>;</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 3,470: | Line 3,470: | ||
╚════════════════════════════════════════════════════════════════════╝ |
╚════════════════════════════════════════════════════════════════════╝ |
||
</pre> |
</pre> |
||
< |
<syntaxhighlight lang="rexx">/*REXX program computes the check digit (last digit) for six or seven character SEDOLs.*/ |
||
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*the uppercase Latin alphabet. */ |
@abcU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*the uppercase Latin alphabet. */ |
||
alphaDigs= '0123456789'@abcU /*legal characters, and then some. */ |
alphaDigs= '0123456789'@abcU /*legal characters, and then some. */ |
||
Line 3,511: | Line 3,511: | ||
sed: say; say 'SEDOL:' sedol; say; return |
sed: say; say 'SEDOL:' sedol; say; return |
||
ser: say; say '***error***' arg(1); call sed; exit 13 |
ser: say; say '***error***' arg(1); call sed; exit 13 |
||
swa: say; say '***warning***' arg(1); say; return</ |
swa: say; say '***warning***' arg(1); say; return</syntaxhighlight> |
||
'''output''' when using the defaults: |
'''output''' when using the defaults: |
||
<pre> |
<pre> |
||
Line 3,528: | Line 3,528: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
see sedol("710889") + nl |
see sedol("710889") + nl |
||
see sedol("B0YBKJ") + nl |
see sedol("B0YBKJ") + nl |
||
Line 3,553: | Line 3,553: | ||
next |
next |
||
return d + (10 - (s % 10)) % 10 |
return d + (10 - (s % 10)) % 10 |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 3,570: | Line 3,570: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
< |
<syntaxhighlight lang="ruby">Sedol_char = "0123456789BCDFGHJKLMNPQRSTVWXYZ" |
||
Sedolweight = [1,3,1,7,3,9] |
Sedolweight = [1,3,1,7,3,9] |
||
Line 3,606: | Line 3,606: | ||
p e |
p e |
||
end |
end |
||
end</ |
end</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,626: | Line 3,626: | ||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
< |
<syntaxhighlight lang="rust"> |
||
fn sedol(input: &str) -> Option<String> { |
fn sedol(input: &str) -> Option<String> { |
||
let weights = vec![1, 3, 1, 7, 3, 9, 1]; |
let weights = vec![1, 3, 1, 7, 3, 9, 1]; |
||
Line 3,673: | Line 3,673: | ||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,690: | Line 3,690: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
< |
<syntaxhighlight 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.size == 7, "SEDOL length must be 6 or 7 characters") |
||
require(s.size == 6 || s(6).asDigit == chksum, "Incorrect SEDOL checksum") |
require(s.size == 6 || s(6).asDigit == chksum, "Incorrect SEDOL checksum") |
||
Line 3,696: | Line 3,696: | ||
def chksum = 10 - ((s zip List(1, 3, 1, 7, 3, 9) map { case (c, w) => c.asDigit * w } sum) % 10) |
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 |
override def toString = s.take(6) + chksum |
||
}</ |
}</syntaxhighlight> |
||
Test cases: |
Test cases: |
||
Line 3,737: | Line 3,737: | ||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
const func char: sedolCheckDigit (in string: sedol) is func |
const func char: sedolCheckDigit (in string: sedol) is func |
||
Line 3,771: | Line 3,771: | ||
writeln(sedol <& sedolCheckDigit(sedol)); |
writeln(sedol <& sedolCheckDigit(sedol)); |
||
end for; |
end for; |
||
end func;</ |
end func;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 3,790: | Line 3,790: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="ruby">func sedol(s) { |
||
die 'No vowels allowed' if (s ~~ /[AEIOU]/); |
die 'No vowels allowed' if (s ~~ /[AEIOU]/); |
||
Line 3,818: | Line 3,818: | ||
).each { |s| |
).each { |s| |
||
say sedol(s); |
say sedol(s); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,836: | Line 3,836: | ||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
{{works with|GNU Smalltalk}} |
{{works with|GNU Smalltalk}} |
||
< |
<syntaxhighlight lang="smalltalk">String extend [ |
||
includesAnyOf: aSet [ |
includesAnyOf: aSet [ |
||
aSet do: [ :e | (self includes: e) ifTrue: [ ^true ] ]. |
aSet do: [ :e | (self includes: e) ifTrue: [ ^true ] ]. |
||
^false |
^false |
||
] |
] |
||
].</ |
].</syntaxhighlight> |
||
< |
<syntaxhighlight lang="smalltalk">Object subclass: SEDOL [ |
||
|weight charList| |
|weight charList| |
||
Line 3,885: | Line 3,885: | ||
] |
] |
||
] |
] |
||
].</ |
].</syntaxhighlight> |
||
< |
<syntaxhighlight lang="smalltalk">|sedol| |
||
sedol := SEDOL new. |
sedol := SEDOL new. |
||
{ '710889'. |
{ '710889'. |
||
Line 3,898: | Line 3,898: | ||
'B0YBKR'. |
'B0YBKR'. |
||
'585284'. |
'585284'. |
||
'B0YBKT' } do: [ :c | (sedol checked: c) displayNl ]</ |
'B0YBKT' } do: [ :c | (sedol checked: c) displayNl ]</syntaxhighlight> |
||
{{works with|Smalltalk/X}} |
{{works with|Smalltalk/X}} |
||
< |
<syntaxhighlight lang="smalltalk">#( |
||
'710889' |
'710889' |
||
'B0YBKJ' |
'B0YBKJ' |
||
Line 3,922: | Line 3,922: | ||
check := (10 - (sum%10)) % 10. |
check := (10 - (sum%10)) % 10. |
||
Transcript showCR: ( in,(Character digitValue:check)) |
Transcript showCR: ( in,(Character digitValue:check)) |
||
].</ |
].</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
7108899 |
7108899 |
||
Line 3,939: | Line 3,939: | ||
{{works with|Db2 LUW}} version 9.7 or higher. |
{{works with|Db2 LUW}} version 9.7 or higher. |
||
With SQL PL: |
With SQL PL: |
||
< |
<syntaxhighlight lang="sql pl"> |
||
--#SET TERMINATOR @ |
--#SET TERMINATOR @ |
||
Line 4,004: | Line 4,004: | ||
RETURN TEXT || CHECK; |
RETURN TEXT || CHECK; |
||
END @ |
END @ |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 4,052: | Line 4,052: | ||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |
||
< |
<syntaxhighlight lang="sml">fun char2value c = |
||
if List.exists (fn x => x = c) (explode "AEIOU") then raise Fail "no vowels" |
if List.exists (fn x => x = c) (explode "AEIOU") then raise Fail "no vowels" |
||
else if Char.isDigit c then ord c - ord #"0" |
else if Char.isDigit c then ord c - ord #"0" |
||
Line 4,077: | Line 4,077: | ||
"B0YBKR", |
"B0YBKR", |
||
"585284", |
"585284", |
||
"B0YBKT" ];</ |
"B0YBKT" ];</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
< |
<syntaxhighlight 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 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} |
variable weight {1 3 1 7 3 9 1} |
||
Line 4,117: | Line 4,117: | ||
assert {$sedol eq $answer} "assertion failed: $sedol ne $answer" |
assert {$sedol eq $answer} "assertion failed: $sedol ne $answer" |
||
puts $sedol |
puts $sedol |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Transact-SQL}}== |
=={{header|Transact-SQL}}== |
||
Line 4,123: | Line 4,123: | ||
Returns empty string if invalid. |
Returns empty string if invalid. |
||
< |
<syntaxhighlight lang="tsql">CREATE FUNCTION [dbo].[fn_CheckSEDOL] |
||
( @SEDOL varchar(50) ) |
( @SEDOL varchar(50) ) |
||
RETURNS varchar(7) |
RETURNS varchar(7) |
||
Line 4,185: | Line 4,185: | ||
-- Return the result of the function |
-- Return the result of the function |
||
RETURN @SEDOL |
RETURN @SEDOL |
||
END</ |
END</syntaxhighlight> |
||
Examples: |
Examples: |
||
Line 4,213: | Line 4,213: | ||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |
||
< |
<syntaxhighlight lang="tuscript"> |
||
$$ MODE TUSCRIPT |
$$ MODE TUSCRIPT |
||
check="1'3'1'7'3'9" |
check="1'3'1'7'3'9" |
||
Line 4,234: | Line 4,234: | ||
PRINT input, " checkdigit: ", checksum |
PRINT input, " checkdigit: ", checksum |
||
ENDLOOP |
ENDLOOP |
||
</syntaxhighlight> |
|||
</lang> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 4,258: | Line 4,258: | ||
to the list of character values. |
to the list of character values. |
||
< |
<syntaxhighlight lang="ursala">#import std |
||
#import nat |
#import nat |
||
Line 4,265: | Line 4,265: | ||
charval = -:@rlXS num alphabet |
charval = -:@rlXS num alphabet |
||
iprod = sum:-0+ product*p/weights+ charval* |
iprod = sum:-0+ product*p/weights+ charval* |
||
checksum = difference/10+ remainder\10+ iprod</ |
checksum = difference/10+ remainder\10+ iprod</syntaxhighlight> |
||
An optimization following the J solution avoids a run-time subtraction |
An optimization following the J solution avoids a run-time subtraction |
||
by complementing the coefficients at compile time using these |
by complementing the coefficients at compile time using these |
||
definitions in place of those above. |
definitions in place of those above. |
||
< |
<syntaxhighlight lang="ursala">weights = difference/*10 <1,3,1,7,3,9> |
||
checksum = remainder\10+ iprod</ |
checksum = remainder\10+ iprod</syntaxhighlight> |
||
A further performance improvement subsumes the character value lookup |
A further performance improvement subsumes the character value lookup |
||
Line 4,277: | Line 4,277: | ||
the version shown below. |
the version shown below. |
||
< |
<syntaxhighlight lang="ursala">lookup = -: (^/~& product^|/~& charval)*lsPrK0/weights alphabet |
||
iprod = sum:-0+ lookup*p/weights</ |
iprod = sum:-0+ lookup*p/weights</syntaxhighlight> |
||
To optimize further, we can build a separate smaller multiplication table for |
To optimize further, we can build a separate smaller multiplication table for |
||
Line 4,285: | Line 4,285: | ||
index directly into the input list. |
index directly into the input list. |
||
< |
<syntaxhighlight lang="ursala">lookups = (-:+ * ^/~&l product^|/charval ~&)* *-* -*weights alphabet |
||
iprod = sum:-0+ gang +^|(~&,~)*lNrXXK9 ^(~&,&h!)* lookups</ |
iprod = sum:-0+ gang +^|(~&,~)*lNrXXK9 ^(~&,&h!)* lookups</syntaxhighlight> |
||
Here is a test program. |
Here is a test program. |
||
< |
<syntaxhighlight lang="ursala">#show+ |
||
examples = ^T(~&,~&h+ %nP+ checksum)*t |
examples = ^T(~&,~&h+ %nP+ checksum)*t |
||
Line 4,302: | Line 4,302: | ||
B0YBKR |
B0YBKR |
||
585284 |
585284 |
||
B0YBKT]-</ |
B0YBKT]-</syntaxhighlight> |
||
output: |
output: |
||
<pre>7108899 |
<pre>7108899 |
||
Line 4,316: | Line 4,316: | ||
=={{header|VBA}}== |
=={{header|VBA}}== |
||
< |
<syntaxhighlight lang="lb">Function getSedolCheckDigit(Input1) |
||
Dim mult(6) As Integer |
Dim mult(6) As Integer |
||
mult(1) = 1: mult(2) = 3: mult(3) = 1 |
mult(1) = 1: mult(2) = 3: mult(3) = 1 |
||
Line 4,341: | Line 4,341: | ||
getSedolCheckDigit = Input1 + CStr((10 - (Total Mod 10)) Mod 10) |
getSedolCheckDigit = Input1 + CStr((10 - (Total Mod 10)) Mod 10) |
||
End Function</ |
End Function</syntaxhighlight> |
||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
Derived from the BASIC version. |
Derived from the BASIC version. |
||
<syntaxhighlight lang="vbscript"> |
|||
<lang VBScript> |
|||
arr = Array("710889",_ |
arr = Array("710889",_ |
||
"B0YBKJ",_ |
"B0YBKJ",_ |
||
Line 4,389: | Line 4,389: | ||
Next |
Next |
||
getSEDOLCheckDigit = (10 - total Mod 10) Mod 10 |
getSEDOLCheckDigit = (10 - total Mod 10) Mod 10 |
||
End Function</ |
End Function</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 4,407: | Line 4,407: | ||
=={{header|Visual FoxPro}}== |
=={{header|Visual FoxPro}}== |
||
< |
<syntaxhighlight lang="vfp"> |
||
#DEFINE ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
#DEFINE ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
||
#DEFINE VOWELS "AEIOU" |
#DEFINE VOWELS "AEIOU" |
||
Line 4,481: | Line 4,481: | ||
RETURN EMPTY(tcMsg) |
RETURN EMPTY(tcMsg) |
||
ENDFUNC |
ENDFUNC |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 4,491: | Line 4,491: | ||
{{libheader|Wren-str}} |
{{libheader|Wren-str}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/str" for Char |
||
import "/fmt" for Conv |
import "/fmt" for Conv |
||
Line 4,527: | Line 4,527: | ||
var ans = (a = sedol.call(test)) ? a : "not valid" |
var ans = (a = sedol.call(test)) ? a : "not valid" |
||
System.print("%(test) -> %(ans)") |
System.print("%(test) -> %(ans)") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 4,545: | Line 4,545: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">string 0; \use zero-terminated strings |
||
func CheckDigit(Str); \Return the check digit for a SEDOL |
func CheckDigit(Str); \Return the check digit for a SEDOL |
||
Line 4,584: | Line 4,584: | ||
CrLf(0); |
CrLf(0); |
||
]; |
]; |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 4,602: | Line 4,602: | ||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
< |
<syntaxhighlight lang="yabasic">data "710889", "B0YBKJ", "406566", "B0YBLH", "228276", "B0YBKL", "557910", "B0YBKR", "585284", "B0YBKT", "B00030", "AB", "B00A03", "" |
||
do |
do |
||
Line 4,627: | Line 4,627: | ||
NEXT |
NEXT |
||
return d$ + CHR$(48 + mod(10 - mod(s, 10), 10)) |
return d$ + CHR$(48 + mod(10 - mod(s, 10), 10)) |
||
end sub</ |
end sub</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
< |
<syntaxhighlight lang="zkl">fcn checksum(text){ |
||
( text.len()!=6 or (text..matches("*[AEIOUaeioua-z]*")) ) and |
( text.len()!=6 or (text..matches("*[AEIOUaeioua-z]*")) ) and |
||
throw(Exception.ValueError("Invalid SEDOL text: "+text)); |
throw(Exception.ValueError("Invalid SEDOL text: "+text)); |
||
Line 4,638: | Line 4,638: | ||
else c.toAsc()-55; |
else c.toAsc()-55; |
||
}).zipWith('*,T(1,3,1,7,3,9)).sum() % 10) % 10; |
}).zipWith('*,T(1,3,1,7,3,9)).sum() % 10) % 10; |
||
}</ |
}</syntaxhighlight> |
||
It sure does look like that trailing %10 is extraneous. It also seems like lower case is implicitly invalid. |
It sure does look like that trailing %10 is extraneous. It also seems like lower case is implicitly invalid. |
||
< |
<syntaxhighlight lang="zkl">T("710889","B0YBKJ","406566","B0YBLH","228276", |
||
"B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030") |
"B0YBKL","557910","B0YBKR","585284","B0YBKT","B00030") |
||
.apply(checksum).println();</ |
.apply(checksum).println();</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |