Data update

This commit is contained in:
Ingy dot Net 2024-04-19 16:56:29 -07:00
parent 0df55f9f24
commit aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions

View file

@ -0,0 +1,39 @@
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

View file

@ -1,25 +1,20 @@
// version 1.1.0
val weights = listOf(1, 3, 1, 7, 3, 9, 1)
val weights = arrayOf(1, 3, 1, 7, 3, 9, 1)
val validChars = (('0'..'9') + ('A'..'Z')).toSet() - "AEIOU".toSet()
fun sedol7(sedol6: String): String {
if (sedol6.length != 6) throw IllegalArgumentException("Length of argument string must be 6")
var sum = 0
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()
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()
val check = (-sum).mod(10)
return sedol6 + ('0' + check)
}
fun main(args: Array<String>) {
val sedol6s = listOf("710889", "B0YBKJ", "406566", "B0YBLH", "228276", "B0YBKL",
"557910", "B0YBKR", "585284", "B0YBKT", "B00030")
for (sedol6 in sedol6s) println("$sedol6 -> ${sedol7(sedol6)}")
fun main() {
val sedol6s = listOf(
"710889", "B0YBKJ", "406566", "B0YBLH", "228276", "B0YBKL",
"557910", "B0YBKR", "585284", "B0YBKT", "B00030"
)
for (sedol6 in sedol6s)
println("$sedol6 -> ${sedol7(sedol6)}")
}

View file

@ -1,4 +1,4 @@
val .csd = f(.code) {
val .csd = fn(.code) {
switch len(.code) {
case 0:
return "nada, zip, zilch"
@ -6,7 +6,7 @@ val .csd = f(.code) {
return "invalid length"
}
if matching(re/[^B-DF-HJ-NP-TV-Z0-9]/, .code) {
if .code -> re/[^B-DF-HJ-NP-TV-Z0-9]/ {
return "invalid character(s)"
}
@ -14,10 +14,10 @@ val .csd = f(.code) {
val .nums = s2n .code
val .sum = for[=0] .i of .nums {
_for += .nums[.i] x .weight[.i]
_for += .nums[.i] * .weight[.i]
}
toString 9 - (.sum - 1) rem 10
string 9 - (.sum - 1) rem 10
}
val .h = h{
@ -50,7 +50,7 @@ for .input in sort(keys .h) {
if len(.d) > 1 {
writeln .input, ": ", .d
} else {
val .expect = toString .h[.input]
val .expect = string .h[.input]
write .input, .d
writeln if .expect == .d {""} else {
$" (SEDOL test failed; expected check digit \.expect;)"}

View file

@ -8,7 +8,7 @@ def checksum(sedol):
tmp = sum(map(lambda ch, weight: char2value(ch) * weight,
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
return str((-tmp) % 10)
for sedol in '''
710889

View file

@ -22,7 +22,7 @@ def sedolCheckSumDigitLR(s):
zip(s, [1, 3, 1, 7, 3, 9]),
Right(0)
)
)(lambda d: Right(str((10 - (d % 10)) % 10)))
)(lambda d: Right(str((-d) % 10)))
# sedolValLR :: Char -> Either String Char