SEDOLs: Difference between revisions
m
→{{header|langur}}
(RPL: add section) |
Langurmonkey (talk | contribs) |
||
(11 intermediate revisions by 5 users not shown) | |||
Line 1,177:
println(addChecksum(sedol.trim()))
}</syntaxhighlight>
=={{header|EasyLang}}==
func$ chksum sedol6$ .
if len sedol6$ <> 6
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
else
return ""
.
sum += h * weights[i]
.
.
repeat
s$ = input
until s$ = ""
print s$ & chksum s$
.
input_data
710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030
=={{header|Elixir}}==
Line 2,325 ⟶ 2,368:
=={{header|Kotlin}}==
<syntaxhighlight lang="
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 {
require(sedol6.all { it in validChars }) {
▲ for (i in 0..5) {
val sum = sedol6.map { it.digitToInt(36) }.zip(weights, Int::times).sum()
▲ val c = sedol6[i]
return sedol6 +
▲ else -> throw IllegalArgumentException("Argument string contains an invalid character")
▲ }
▲ sum += v * weights[i]
▲ }
▲ val check = (10 - (sum % 10)) % 10
}
fun main(
val sedol6s = listOf(
"557910", "B0YBKR", "585284", "B0YBKT", "B00030"
for (sedol6 in sedol6s) println("$sedol6 -> ${sedol7(sedol6)}")▼
)
▲}</syntaxhighlight>
for (sedol6 in sedol6s)
}
</syntaxhighlight>
{{out}}
Line 2,368 ⟶ 2,408:
=={{header|langur}}==
{{trans|Go}}
<syntaxhighlight lang="langur">val .csd = fn(.code) {
case 0:
return "nada, zip, zilch"
Line 2,377 ⟶ 2,416:
}
if
return "invalid character(s)"
}
Line 2,385 ⟶ 2,424:
val .nums = s2n .code
val .sum = for[=0] .i of .nums {
_for += .nums[.i]
}
}
val .h =
# invalid...
"": 0,
Line 2,421 ⟶ 2,460:
writeln .input, ": ", .d
} else {
val .expect =
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((
for sedol in '''
Line 3,182 ⟶ 3,248:
Right(0)
)
)(lambda d: Right(str((
Line 4,561 ⟶ 4,627:
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
import "./fmt" for Conv
var sedol = Fn.new { |s|
|