Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/SEDOLs/D/sedols-1.d
Normal file
20
Task/SEDOLs/D/sedols-1.d
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import std.stdio, std.algorithm, std.string, std.numeric, std.ascii;
|
||||
|
||||
char checksum(in char[] sedol) pure @safe /*@nogc*/
|
||||
in {
|
||||
assert(sedol.length == 6);
|
||||
foreach (immutable c; sedol)
|
||||
assert(c.isDigit || (c.isUpper && !"AEIOU".canFind(c)));
|
||||
} out (result) {
|
||||
assert(result.isDigit);
|
||||
} body {
|
||||
static immutable c2v = (in dchar c) => c.isDigit ? c - '0' : (c - 'A' + 10);
|
||||
immutable int d = sedol.map!c2v.dotProduct([1, 3, 1, 7, 3, 9]);
|
||||
return digits[10 - (d % 10)];
|
||||
}
|
||||
|
||||
void main() {
|
||||
foreach (const sedol; "710889 B0YBKJ 406566 B0YBLH 228276
|
||||
B0YBKL 557910 B0YBKR 585284 B0YBKT".split)
|
||||
writeln(sedol, sedol.checksum);
|
||||
}
|
||||
38
Task/SEDOLs/D/sedols-2.d
Normal file
38
Task/SEDOLs/D/sedols-2.d
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import std.stdio, std.algorithm, std.string, std.numeric, std.ascii;
|
||||
|
||||
char sedolChecksum(in char[] sedol) pure nothrow @safe /*@nogc*/
|
||||
in {
|
||||
assert(sedol.length == 6, "SEDOL must be 6 chars long.");
|
||||
enum uint mask = 0b11_1110_1111_1011_1110_1110_1110;
|
||||
|
||||
foreach (immutable c; sedol)
|
||||
assert(c.isDigit ||
|
||||
(c > 'A' && c <= 'Z' && ((1U << (c - 'A')) & mask)),
|
||||
"SEDOL with wrong char.");
|
||||
} out(result) {
|
||||
assert(result.isDigit);
|
||||
static int c2v(in dchar c) pure nothrow @safe @nogc {
|
||||
return c.isDigit ? c - '0' : c - 'A' + 10;
|
||||
}
|
||||
immutable int d = sedol.map!c2v.dotProduct([1, 3, 1, 7, 3, 9]);
|
||||
assert((d + result - '0') % 10 == 0);
|
||||
} body {
|
||||
static immutable int[] weights = [1, 3, 1, 7, 3, 9];
|
||||
|
||||
int sum = 0;
|
||||
foreach (immutable i, immutable c; sedol) {
|
||||
if (c.isDigit)
|
||||
sum += (c - '0') * weights[i];
|
||||
else
|
||||
sum += (c - 'A' + 10) * weights[i];
|
||||
}
|
||||
|
||||
return '0' + 10 - (sum % 10);
|
||||
}
|
||||
|
||||
void main() {
|
||||
foreach (immutable s; ["710889", "B0YBKJ", "406566", "B0YBLH",
|
||||
"228276", "B0YBKL", "557910", "B0YBKR",
|
||||
"585284", "B0YBKT"])
|
||||
writeln(s, s.sedolChecksum);
|
||||
}
|
||||
9
Task/SEDOLs/D/sedols-3.d
Normal file
9
Task/SEDOLs/D/sedols-3.d
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
void main() {
|
||||
import std.stdio, std.algorithm, std.string, std.numeric,std.ascii;
|
||||
|
||||
foreach (const s; "710889 B0YBKJ 406566 B0YBLH 228276
|
||||
B0YBKL 557910 B0YBKR 585284 B0YBKT".split)
|
||||
writeln(s, '0' + 10 - s
|
||||
.map!(c => c.isDigit ? c - '0' : c - 'A' + 10)
|
||||
.dotProduct([1, 3, 1, 7, 3, 9]) % 10);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue