diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-12-11 23:20:06 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-11 23:20:06 +0000 |
| commit | 5a16c06bc68432b5fdb366d4dcc69529cd425ee0 (patch) | |
| tree | e246490b7bb1149b48c5be1676bbc67a01071b2c /challenge-194 | |
| parent | 717c133073f8fdc40f4aa05aea0e69778b179a10 (diff) | |
| parent | bcaa98c386bca18260843a58f9d21a82a624fc52 (diff) | |
| download | perlweeklychallenge-club-5a16c06bc68432b5fdb366d4dcc69529cd425ee0.tar.gz perlweeklychallenge-club-5a16c06bc68432b5fdb366d4dcc69529cd425ee0.tar.bz2 perlweeklychallenge-club-5a16c06bc68432b5fdb366d4dcc69529cd425ee0.zip | |
Merge pull request #7239 from E7-87-83/newt
Week 194
Diffstat (limited to 'challenge-194')
| -rw-r--r-- | challenge-194/cheok-yin-fung/perl/ch-1.pl | 25 | ||||
| -rw-r--r-- | challenge-194/cheok-yin-fung/perl/ch-2.pl | 23 |
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; |
