aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCY Fung <fungcheokyin@gmail.com>2022-12-12 05:07:37 +0800
committerCY Fung <fungcheokyin@gmail.com>2022-12-12 05:07:37 +0800
commitbcaa98c386bca18260843a58f9d21a82a624fc52 (patch)
tree691398e42b5848c44e23b27d75c099c9270fae0c
parent7554512a5def78d9b0a73e8a1b66ef72c4aa174a (diff)
downloadperlweeklychallenge-club-bcaa98c386bca18260843a58f9d21a82a624fc52.tar.gz
perlweeklychallenge-club-bcaa98c386bca18260843a58f9d21a82a624fc52.tar.bz2
perlweeklychallenge-club-bcaa98c386bca18260843a58f9d21a82a624fc52.zip
Week 194
-rw-r--r--challenge-194/cheok-yin-fung/perl/ch-1.pl25
-rw-r--r--challenge-194/cheok-yin-fung/perl/ch-2.pl23
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-194/cheok-yin-fung/perl/ch-1.pl b/challenge-194/cheok-yin-fung/perl/ch-1.pl
new file mode 100644
index 0000000000..978abdcf4c
--- /dev/null
+++ b/challenge-194/cheok-yin-fung/perl/ch-1.pl
@@ -0,0 +1,25 @@
+use v5.30.0;
+use warnings;
+
+sub dc {
+ for my $d (reverse 0..9) {
+ my $clock = $_[0];
+ $clock =~ s/\?/$d/g;
+ $clock =~ m/(\d{2}):(\d{2})/;
+ my ($h, $m) = ($1, $2);
+ $h =~ s/^0//;
+ $m =~ s/^0//;
+ if ($h < 24 && $m < 60) {
+ return $d;
+ }
+ }
+}
+
+
+use Test::More tests=>6;
+ok dc("?5:00") == 1;
+ok dc("?3:00") == 2;
+ok dc("1?:00") == 9;
+ok dc("2?:00") == 3;
+ok dc("12:?5") == 5;
+ok dc("12:5?") == 9;
diff --git a/challenge-194/cheok-yin-fung/perl/ch-2.pl b/challenge-194/cheok-yin-fung/perl/ch-2.pl
new file mode 100644
index 0000000000..f0ac1c0692
--- /dev/null
+++ b/challenge-194/cheok-yin-fung/perl/ch-2.pl
@@ -0,0 +1,23 @@
+use v5.30.0;
+use warnings;
+
+sub fe {
+ my $s = $_[0];
+ my %alphabet;
+ $alphabet{$_} = 1 for split "", $s;
+ my %freq;
+ my $minfreq = scalar split "", $s;
+ for my $w (keys %alphabet) {
+ $freq{$w} = scalar grep {$_ eq $w} split "", $s;
+ $minfreq = $freq{$w} if $minfreq > $freq{$w};
+ }
+ my $ans = 0;
+ $ans += $freq{$_} - $minfreq foreach keys %freq;
+ return $ans;
+}
+
+use Test::More tests=>4;
+ok fe("abbc") == 1;
+ok fe("xyzyyxz") == 1;
+ok fe("xzxz") == 0;
+ok fe("xxyyz") == 2;