SEDOLs: Difference between revisions
m
→{{header|langur}}
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: future-proof for 5.36, explicit :prototype) |
Langurmonkey (talk | contribs) |
||
(12 intermediate revisions by 6 users not shown) | |||
Line 1,177:
println(addChecksum(sedol.trim()))
}</syntaxhighlight>
=={{header|EasyLang}}==
<syntaxhighlight>
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
</syntaxhighlight>
=={{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()
fun sedol7(sedol6: String): String {
require(sedol6.all { it in validChars }) { "Argument string contains an invalid character" }
val sum = sedol6.map { it.digitToInt(36) }.zip(weights, Int::times).sum()
return sedol6 +
}
fun main(
val sedol6s = listOf(
"557910", "B0YBKR", "585284", "B0YBKT", "B00030"
)
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) {
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>
{{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 3,598 ⟶ 3,664:
B0YBKT7
B000300
</pre>
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! RPL code
! Comment
|-
|
≪
{ 1 3 1 7 3 9 } → weights
≪ 0 1 6 '''FOR''' j
OVER j DUP SUB NUM
'''IF''' DUP 65 ≥ '''THEN''' 7 - '''END''' 48 -
weights j GET * +
'''NEXT'''
10 SWAP OVER MOD - 10 MOD →STR +
≫ ≫ ''''→7DOL'''' STO
|
'''→7DOL''' ''( "SEDOL6" -- "SEDOL7" ) ''
store weights
sum=0 ; for j = 1 to 6
get jth character of SEDOL
convert it to its index
sum += index * weight
check = mod(10-mod(sum,10),10)
.
|}
{{in}}
<pre>
≪ { }
{ "710889" "B0YBKJ" "406566" "B0YBLH" "228276" "B0YBKL" "557910" "B0YBKR" "585284" "B0YBKT" "B00030" }
1 OVER SIZE FOR j DUP j GET →7DOL SWAP + SWAP NEXT DROP
≫ EVAL
</pre>
{{out}}
<pre>
1: { "7108899" "B0YBKJ7" "4065663" "B0YBLH2" "2282765" "B0YBKL9" "5579107" "B0YBKR5" "5852842" "B0YBKT7" "B000300" }
</pre>
Line 4,522 ⟶ 4,627:
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
import "./fmt" for Conv
var sedol = Fn.new { |s|
|