tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
26
Task/SEDOLs/Perl/sedols.pl
Normal file
26
Task/SEDOLs/Perl/sedols.pl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use List::Util qw(sum);
|
||||
use POSIX qw(strtol);
|
||||
|
||||
sub zip(&\@\@) {
|
||||
my $f = shift;
|
||||
my @a = @{shift()};
|
||||
my @b = @{shift()};
|
||||
my @result;
|
||||
push(@result, $f->(shift @a, shift @b)) while @a && @b;
|
||||
return @result;
|
||||
}
|
||||
|
||||
my @weights = (1, 3, 1, 7, 3, 9);
|
||||
sub sedol($) {
|
||||
my $s = shift;
|
||||
$s =~ /[AEIOU]/ and die "No vowels";
|
||||
my @vs = map {(strtol $_, 36)[0]} split //, $s;
|
||||
my $checksum = sum (zip {$_[0] * $_[1]} @vs, @weights);
|
||||
my $check_digit = (10 - $checksum % 10) % 10;
|
||||
return $s . $check_digit;
|
||||
}
|
||||
|
||||
while (<>) {
|
||||
chomp;
|
||||
print sedol($_), "\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue