aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2022-12-05 16:00:58 +0000
committerNiels van Dijke <perlboy@cpan.org>2022-12-05 16:00:58 +0000
commit6e5d2292148456a658b5c543f684bd2f97d69778 (patch)
treeceb7f9a17236d40dd755f7287a6c38bede9410e6
parent4824fac55259f93f017fbe28fced25070cf8c71b (diff)
downloadperlweeklychallenge-club-6e5d2292148456a658b5c543f684bd2f97d69778.tar.gz
perlweeklychallenge-club-6e5d2292148456a658b5c543f684bd2f97d69778.tar.bz2
perlweeklychallenge-club-6e5d2292148456a658b5c543f684bd2f97d69778.zip
Task 1 - More robust, add length check
-rwxr-xr-xchallenge-194/perlboy1967/perl/ch-1.pl6
1 files changed, 3 insertions, 3 deletions
diff --git a/challenge-194/perlboy1967/perl/ch-1.pl b/challenge-194/perlboy1967/perl/ch-1.pl
index 8826c9ba6b..3e36138700 100755
--- a/challenge-194/perlboy1967/perl/ch-1.pl
+++ b/challenge-194/perlboy1967/perl/ch-1.pl
@@ -23,13 +23,13 @@ use Test::More;
sub highestDigit ($) {
- state $c = { -1=>-1, 0=>2, 1=>9, 2=>-1, 3=>5, 4=>9 };
+ state $c = { 0=>2, 1=>9, 2=>-1, 3=>5, 4=>9 };
- ($_[0] =~ y/?/?/) != 1 ? -1 : $c->{index($_[0],'?')}
+ (length($_[0]) == 5 && $_[0] =~ y/?/?/) == 1 ? $c->{index($_[0],'?')} // -1 : -1;
}
-my %t = qw(?0:00 2 1?:00 9 10:?2 5 12:1? 9 ??:00 -1 00?00 -1);
+my %t = qw(?0:00 2 1?:00 9 10:?2 5 12:1? 9 ??:00 -1 00?00 -1 00:00? -1 ?00:00 -1);
for (sort keys %t) {
is(highestDigit($_),$t{$_},"highestDigit('$_')");