Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,20 +1,20 @@
import std.stdio, std.algorithm, std.string, std.numeric, std.ascii;
char checksum(in char[] sedol)
char checksum(in char[] sedol) pure @safe /*@nogc*/
in {
assert(sedol.length == 6);
foreach (c; sedol)
assert(isDigit(c) || (isUpper(c) && !canFind("AEIOU", c)));
foreach (immutable c; sedol)
assert(c.isDigit || (c.isUpper && !"AEIOU".canFind(c)));
} out (result) {
assert(isDigit(result));
assert(result.isDigit);
} body {
static int c2v(in dchar c){ return isDigit(c) ? c-'0' : c-'A'+10; }
immutable int d = sedol.map!c2v().dotProduct([1,3,1,7,3,9]);
return '0' + 10 - (d % 10);
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 (sedol; "710889 B0YBKJ 406566 B0YBLH 228276
B0YBKL 557910 B0YBKR 585284 B0YBKT".split())
writeln(sedol, checksum(sedol));
foreach (const sedol; "710889 B0YBKJ 406566 B0YBLH 228276
B0YBKL 557910 B0YBKR 585284 B0YBKT".split)
writeln(sedol, sedol.checksum);
}

View file

@ -1,6 +1,6 @@
import std.stdio, std.algorithm, std.string, std.numeric, std.ascii;
char sedolChecksum(in char[] sedol) pure nothrow
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;
@ -11,13 +11,13 @@ in {
"SEDOL with wrong char.");
} out(result) {
assert(result.isDigit);
static int c2v(in dchar c) pure nothrow {
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 {
enum int[] weights = [1, 3, 1, 7, 3, 9];
static immutable int[] weights = [1, 3, 1, 7, 3, 9];
int sum = 0;
foreach (immutable i, immutable c; sedol) {

View file

@ -1,12 +1,9 @@
import std.stdio, std.algorithm, std.string, std.numeric;
auto checksum(string s) {
auto m = s.map!q{ a>='0' && a<='9' ? a-'0' : a-'A'+10 }();
return '0' + 10 - m.dotProduct([1,3,1,7,3,9]) % 10;
}
void main() {
foreach (sedol; "710889 B0YBKJ 406566 B0YBLH 228276
B0YBKL 557910 B0YBKR 585284 B0YBKT".split())
writeln(sedol, sedol.checksum());
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);
}