aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-194/perlboy1967/perl/ch-1.pl22
1 files changed, 17 insertions, 5 deletions
diff --git a/challenge-194/perlboy1967/perl/ch-1.pl b/challenge-194/perlboy1967/perl/ch-1.pl
index f39fc1a5c3..ba79036fb6 100755
--- a/challenge-194/perlboy1967/perl/ch-1.pl
+++ b/challenge-194/perlboy1967/perl/ch-1.pl
@@ -23,13 +23,25 @@ use Test::More;
sub highestDigit ($) {
- state $c = { 0=>2, 1=>9, 2=>-1, 3=>5, 4=>9 };
-
- length($_[0]) == 5 && ($_[0] =~ y/?/?/) == 1 ? $c->{index($_[0],'?')} // -1 : -1;
+ if ($_[0] !~ m#^[\d\?][\d\?]:[\d\?][\d\?]$# or
+ ($_[0] =~ y/?/?/) != 1) {
+ return -1;
+ } else {
+ my $i = index($_[0],'?');
+ if (0) { } # Do nothing, just look pretty in code
+ elsif ($i == 0) { return substr($_[0],1,1) < 4 ? 2 : 1 }
+ elsif ($i == 1) { return substr($_[0],0,1) == 2 ? 3 : 9 }
+ elsif ($i == 2) { return -1 }
+ elsif ($i == 3) { return 5 }
+ elsif ($i == 4) { return 9 }
+ }
}
-
-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);
+my %t = qw(
+ ?5:00 1 ?3:00 2 1?:00 9 2?:00 3 12:?5 5 12:5? 9
+ 00?00 -1 ??:00 -1 00:?? -1 0?:?0 -1 ?0:0? -1 ????? -1
+ ?00:00 -1 ???:00 -1 00??00 -1 00??00 -1 00:??0 -1 0?:00? -1
+);
for (sort keys %t) {
is(highestDigit($_),$t{$_},"highestDigit('$_')");