aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-255/perlboy1967/perl/ch1.pl38
-rwxr-xr-xchallenge-255/perlboy1967/perl/ch2.pl38
2 files changed, 76 insertions, 0 deletions
diff --git a/challenge-255/perlboy1967/perl/ch1.pl b/challenge-255/perlboy1967/perl/ch1.pl
new file mode 100755
index 0000000000..e2946127cb
--- /dev/null
+++ b/challenge-255/perlboy1967/perl/ch1.pl
@@ -0,0 +1,38 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 255
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-255
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Odd Character
+Submitted by: Mohammad Sajid Anwar
+
+You are given two strings, $s and $t. The string $t is generated using the shuffled
+characters of the string $s with an additional character.
+
+Write a script to find the additional character in the string $t.
+
+=cut
+
+use v5.32;
+use feature qw(signatures);
+use common::sense;
+
+use Test2::V0;
+
+use List::MoreUtils qw(firstidx);
+
+sub oddCharacter ($s,$t) {
+ my @s = sort split //, $s;
+ my @t = sort split //, $t;
+ return $t[firstidx { $s[$_] ne $t[$_] } 0 .. $#s];
+}
+
+is(oddCharacter('Perl','Preel'),'e');
+is(oddCharacter('Weekly','Weeakly'),'a');
+is(oddCharacter('Box','Boxy'),'y');
+
+done_testing;
diff --git a/challenge-255/perlboy1967/perl/ch2.pl b/challenge-255/perlboy1967/perl/ch2.pl
new file mode 100755
index 0000000000..2dd8380bce
--- /dev/null
+++ b/challenge-255/perlboy1967/perl/ch2.pl
@@ -0,0 +1,38 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 255
+- https://theweeklychallenge.org/blog/perl-weekly-challenge-255
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Most Frequent Word
+Submitted by: Mohammad Sajid Anwar
+
+You are given a paragraph $p and a banned word $w.
+
+Write a script to return the most frequent word that is not banned.
+
+=cut
+
+use v5.32;
+use feature qw(signatures);
+use common::sense;
+
+use Test2::V0;
+
+use List::Util qw(max);
+use List::MoreUtils qw(frequency);
+
+sub almostFrequentWord ($p,$ban) {
+ my %f = frequency grep !/$ban/, split /\W+/, $p;
+ my %w; push(@{$w{$f{$_}}},$_) for (keys %f);
+ $w{max(keys %w)};
+}
+
+is(almostFrequentWord('five dot three dot three','dot'),['three']);
+is(almostFrequentWord('one plus one plus one equals three','one'),['plus']);
+
+done_testing;
+