diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-10-26 09:52:33 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-10-26 09:52:33 +0100 |
| commit | 4fbb301ccb5620c8bcee20462bd1bb8145b0d13c (patch) | |
| tree | ca2cd6d56d2437c433c0913480dd769a0566911b /challenge-135 | |
| parent | de4d4e92a64a4cd61ae6db8da41662c88553772a (diff) | |
| download | perlweeklychallenge-club-4fbb301ccb5620c8bcee20462bd1bb8145b0d13c.tar.gz perlweeklychallenge-club-4fbb301ccb5620c8bcee20462bd1bb8145b0d13c.tar.bz2 perlweeklychallenge-club-4fbb301ccb5620c8bcee20462bd1bb8145b0d13c.zip | |
Whitespace
Diffstat (limited to 'challenge-135')
| -rw-r--r-- | challenge-135/paulo-custodio/perl/ch-1.pl | 10 | ||||
| -rw-r--r-- | challenge-135/paulo-custodio/perl/ch-2.pl | 46 | ||||
| -rw-r--r-- | challenge-135/paulo-custodio/python/ch-1.py | 4 | ||||
| -rw-r--r-- | challenge-135/paulo-custodio/python/ch-2.py | 8 |
4 files changed, 34 insertions, 34 deletions
diff --git a/challenge-135/paulo-custodio/perl/ch-1.pl b/challenge-135/paulo-custodio/perl/ch-1.pl index ebb2200c2c..9c8c982e26 100644 --- a/challenge-135/paulo-custodio/perl/ch-1.pl +++ b/challenge-135/paulo-custodio/perl/ch-1.pl @@ -3,9 +3,9 @@ # TASK #1 > Middle 3-digits # Submitted by: Mohammad S Anwar # You are given an integer. -# +# # Write a script find out the middle 3-digits of the given integer, if possible otherwise throw sensible error. -# +# # Example 1 # Input: $n = 1234567 # Output: 345 @@ -24,11 +24,11 @@ use Modern::Perl; my $n = abs(shift||0); my $len = length($n); if ($len%2==0) { - say "even number of digits"; + say "even number of digits"; } elsif ($len<3) { - say "too short"; + say "too short"; } else { - say substr($n, ($len-3)/2, 3); + say substr($n, ($len-3)/2, 3); } diff --git a/challenge-135/paulo-custodio/perl/ch-2.pl b/challenge-135/paulo-custodio/perl/ch-2.pl index aad313eac5..d5016cb86c 100644 --- a/challenge-135/paulo-custodio/perl/ch-2.pl +++ b/challenge-135/paulo-custodio/perl/ch-2.pl @@ -3,12 +3,12 @@ # TASK #2 > Validate SEDOL # Submitted by: Mohammad S Anwar # You are given 7-characters alphanumeric SEDOL. -# -# Write a script to validate the given SEDOL. Print 1 if it is a valid SEDOL +# +# Write a script to validate the given SEDOL. Print 1 if it is a valid SEDOL # otherwise 0. -# +# # For more information about SEDOL, please checkout the wikipedia page. -# +# # Example 1 # Input: $SEDOL = '2936921' # Output: 1 @@ -25,26 +25,26 @@ my $SEDOL = shift||""; say check_sedol($SEDOL); sub check_sedol { - my($str) = @_; - return 0 unless $str =~ /^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}[0-9]$/; - my $input = substr($str, 0, 6); - my $check_digit = compute_check_digit($input); - if ($input.$check_digit eq $str) { - return 1; - } - else { - return 0; - } + my($str) = @_; + return 0 unless $str =~ /^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}[0-9]$/; + my $input = substr($str, 0, 6); + my $check_digit = compute_check_digit($input); + if ($input.$check_digit eq $str) { + return 1; + } + else { + return 0; + } } sub compute_check_digit { - my($input) = @_; - my @weight = (1, 3, 1, 7, 3, 9); - my @input = map {$_ ge 'A' ? ord($_)-ord('A')+10 : ord($_)-ord('0')} - split //, $input; - my $sum = 0; - for my $i (0..$#weight) { - $sum += $input[$i] * $weight[$i]; - } - return (10-$sum%10); + my($input) = @_; + my @weight = (1, 3, 1, 7, 3, 9); + my @input = map {$_ ge 'A' ? ord($_)-ord('A')+10 : ord($_)-ord('0')} + split //, $input; + my $sum = 0; + for my $i (0..$#weight) { + $sum += $input[$i] * $weight[$i]; + } + return (10-$sum%10); } diff --git a/challenge-135/paulo-custodio/python/ch-1.py b/challenge-135/paulo-custodio/python/ch-1.py index 389816b534..b310faccc3 100644 --- a/challenge-135/paulo-custodio/python/ch-1.py +++ b/challenge-135/paulo-custodio/python/ch-1.py @@ -3,9 +3,9 @@ # TASK #1 > Middle 3-digits # Submitted by: Mohammad S Anwar # You are given an integer. -# +# # Write a script find out the middle 3-digits of the given integer, if possible otherwise throw sensible error. -# +# # Example 1 # Input: $n = 1234567 # Output: 345 diff --git a/challenge-135/paulo-custodio/python/ch-2.py b/challenge-135/paulo-custodio/python/ch-2.py index 9f1bb2594a..fe3641e471 100644 --- a/challenge-135/paulo-custodio/python/ch-2.py +++ b/challenge-135/paulo-custodio/python/ch-2.py @@ -3,12 +3,12 @@ # TASK #2 > Validate SEDOL # Submitted by: Mohammad S Anwar # You are given 7-characters alphanumeric SEDOL. -# -# Write a script to validate the given SEDOL. Print 1 if it is a valid SEDOL +# +# Write a script to validate the given SEDOL. Print 1 if it is a valid SEDOL # otherwise 0. -# +# # For more information about SEDOL, please checkout the wikipedia page. -# +# # Example 1 # Input: $SEDOL = '2936921' # Output: 1 |
