diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-04-30 11:19:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-30 11:19:07 +0100 |
| commit | 21981bad9b4dbde7ded5f4bce4e5508560fa6843 (patch) | |
| tree | 8b0cd08bdef61e8d803d044020cc55ee2ff54858 | |
| parent | e75457023d33f23848ed03d1cb9aa412a2890569 (diff) | |
| parent | d619bf613d4ee483ea735cf315ad707f9cf43277 (diff) | |
| download | perlweeklychallenge-club-21981bad9b4dbde7ded5f4bce4e5508560fa6843.tar.gz perlweeklychallenge-club-21981bad9b4dbde7ded5f4bce4e5508560fa6843.tar.bz2 perlweeklychallenge-club-21981bad9b4dbde7ded5f4bce4e5508560fa6843.zip | |
Merge pull request #6025 from LubosKolouch/master
feat(challenge-162/lubos-kolouch/perl/ch-1.pl): Challenge 162 LK Perl Task 1
| -rw-r--r-- | challenge-162/lubos-kolouch/perl/ch-1.pl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-162/lubos-kolouch/perl/ch-1.pl b/challenge-162/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..dc39b9f0f6 --- /dev/null +++ b/challenge-162/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,29 @@ +use strict; +use warnings; + +sub calc_isbn_digit { + my $what = shift; + + my $mul = 1; + + my $sum = 0; + + for my $char ( split //, $what ) { + next unless $char =~ /\d/; + + $sum += $char * $mul; + + $mul = $mul == 1 ? 3 : 1; + } + + $sum %= 10; + $sum = 10 - $sum; + $sum = 0 if $sum == 10; + + return $sum; +} + +use Test::More; + +is( calc_isbn_digit('978-0-306-40615-?'), 7 ); +done_testing; |
