SEDOLs: Difference between revisions

1,058 bytes added ,  16 days ago
m
(RPL: add section)
(11 intermediate revisions by 5 users not shown)
Line 1,177:
println(addChecksum(sedol.trim()))
}</syntaxhighlight>
 
=={{header|EasyLang}}==
}</syntaxhighlight>
val weights[] = listOf([ 1, 3, 1, 7, 3, 9, 1)]
func$ chksum sedol6$ .
if len sedol6$ <> 6
return }""
}.
for (i in 0..5)to {6
val c$ = substr sedol6[i]$ 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
sum +h -= v65 *- weights[i]10
else
return ""
.
sum += h * weights[i]
.
return val check =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}}==
Line 2,325 ⟶ 2,368:
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scalakotlin">// version 1.1.0
val weights = arrayOf(1, 3, 1, 7, 3, 9, 1)
 
val validChars = (('0'..'9') + ('A'..'Z')).toSet() - "AEIOU".toSet()
val weights = listOf(1, 3, 1, 7, 3, 9, 1)
 
fun sedol7(sedol6: String): String {
if require(sedol6.length !== 6) throw{ IllegalArgumentException("Length of argument string must be 6") }
require(sedol6.all { it in validChars }) { else -> throw IllegalArgumentException("Argument string contains an invalid character") }
var sum = 0
 
for (i in 0..5) {
val sum = sedol6.map { it.digitToInt(36) }.zip(weights, Int::times).sum()
val c = sedol6[i]
val vcheck = when (c-sum).mod(10) {
return sedol6 + in ('0'..'9' ->+ c.toInt(check) - 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)}")
)
}</syntaxhighlight>
for (sedol6 in sedol6s)
for (sedol6 in sedol6s) println("$sedol6 -> ${sedol7(sedol6)}")
}
</syntaxhighlight>
 
{{out}}
Line 2,368 ⟶ 2,408:
=={{header|langur}}==
{{trans|Go}}
<syntaxhighlight lang="langur">val .csd = fn(.code) {
{{works with|langur|0.8.10}}
<syntaxhighlight lang="langur">val .csd = fswitch len(.code) {
given len(.code) {
case 0:
return "nada, zip, zilch"
Line 2,377 ⟶ 2,416:
}
 
if matching(.code -> re/[^B-DF-HJ-NP-TV-Z0-9]/, .code) {
return "invalid character(s)"
}
Line 2,385 ⟶ 2,424:
val .nums = s2n .code
val .sum = for[=0] .i of .nums {
_for += .nums[.i] x* .weight[.i]
}
 
toStringstring 9 - (.sum - 1) rem 10
}
 
val .h = h{
# invalid...
"": 0,
Line 2,421 ⟶ 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;)"}
}
}
}</syntaxhighlight>
</syntaxhighlight>
 
{{out}}
Line 2,913 ⟶ 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}}==
Line 3,138 ⟶ 3,204:
sedol, sedolweight)
)
return str((10 - (tmp % 10)) % 10)
 
for sedol in '''
Line 3,182 ⟶ 3,248:
Right(0)
)
)(lambda d: Right(str((10 - (d % 10)) % 10)))
 
 
Line 4,561 ⟶ 4,627:
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./str" for Char
import "./fmt" for Conv
 
var sedol = Fn.new { |s|
885

edits