aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-194/perlboy1967/perl/ch-1.pl38
-rwxr-xr-xchallenge-194/perlboy1967/perl/ch-2.pl41
2 files changed, 79 insertions, 0 deletions
diff --git a/challenge-194/perlboy1967/perl/ch-1.pl b/challenge-194/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..4b4638403d
--- /dev/null
+++ b/challenge-194/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,38 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 194
+ - https://theweeklychallenge.org/blog/perl-weekly-challenge-194/#TASK1
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Digital Clock
+Submitted by: Mohammad S Anwar
+
+You are given time in the format hh:mm with one missing digit.
+
+Write a script to find the highest digit between 0-9 that makes it valid time.
+
+=cut
+
+use v5.16;
+use warnings;
+
+use Test::More;
+
+
+sub highestDigit ($) {
+ state $c = { -1=>-1, 0=>2, 1=>9, 2=>-1, 3=>5, 4=>9 };
+
+ $c->{index($_[0],'?')}
+}
+
+
+my %t = qw(?0:00 2 1?:00 9 10:?2 5 12:1? 9);
+
+for (sort keys %t) {
+ is(highestDigit($_),$t{$_},"highestDigit('$_')");
+}
+
+done_testing;
diff --git a/challenge-194/perlboy1967/perl/ch-2.pl b/challenge-194/perlboy1967/perl/ch-2.pl
new file mode 100755
index 0000000000..41ae391e34
--- /dev/null
+++ b/challenge-194/perlboy1967/perl/ch-2.pl
@@ -0,0 +1,41 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 194
+ - https://theweeklychallenge.org/blog/perl-weekly-challenge-194/#TASK2
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Frequency Equalizer
+Submitted by: Mohammad S Anwar
+
+You are given a string made of alphabetic characters only, a-z.
+
+Write a script to determine whether removing only one character can make
+the frequency of the remaining characters the same.
+
+=cut
+
+use v5.16;
+use warnings;
+
+use List::MoreUtils qw(frequency minmax);
+
+use Test::More;
+
+
+sub freqEqual ($) {
+ my %f = frequency(split//,$_[0]);
+ my ($min,$max) = minmax(keys {reverse %f});
+ return $min == $max-1 ? 1 : 0;
+}
+
+
+my %t = qw(abbc 1 xyzyyxz 1 xzxz 0);
+
+for (sort keys %t) {
+ is(freqEqual($_),$t{$_},"freqEqual('$_')");
+}
+
+done_testing;