aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-135/james-smith/perl/ch-2.pl8
1 files changed, 8 insertions, 0 deletions
diff --git a/challenge-135/james-smith/perl/ch-2.pl b/challenge-135/james-smith/perl/ch-2.pl
index 1e0097ff0d..9c09365af4 100644
--- a/challenge-135/james-smith/perl/ch-2.pl
+++ b/challenge-135/james-smith/perl/ch-2.pl
@@ -19,6 +19,7 @@ my @TESTS = (
);
is( is_sedol($_->[0]), $_->[1] ) for @TESTS;
+is( is_sedol_compact($_->[0]), $_->[1] ) for @TESTS;
done_testing();
@@ -36,3 +37,10 @@ sub is_sedol {
return $t % 10 ? 0 : 1;
}
+sub is_sedol_compact {
+ return 0 unless$_[0]=~/^[0-9B-HJ-NP-TW-Z]{6}\d$/;
+ my($t,@w)=qw(0 1 3 1 7 3 9 1);
+ $t+=(/\d/?$_:-55+ord$_)*shift@w for split//,$_[0];
+ $t%10?0:1;
+}
+