RosettaCodeData/Task/SEDOLs/Groovy/sedols-1.groovy
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

10 lines
343 B
Groovy

def checksum(text) {
assert text.size() == 6 && !text.toUpperCase().find(/[AEIOU]+/) : "Invalid SEDOL text: $text"
def sum = 0
(0..5).each { index ->
sum += Character.digit(text.charAt(index), 36) * [1, 3, 1, 7, 3, 9][index]
}
text + (10 - (sum % 10)) % 10
}
String.metaClass.sedol = { this.&checksum(delegate) }