aboutsummaryrefslogtreecommitdiff
path: root/challenge-255/barroff/perl
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2024-02-11 22:44:52 +0100
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2024-02-11 22:44:52 +0100
commit7917cf7c630338e3ec9c656e90108baa90bb0c25 (patch)
tree9b28c98fed027b9d0f6a6ee3e0c6c56fde3457b5 /challenge-255/barroff/perl
parent37ada6711db701f816594d7d4b89a3aac8a79b1b (diff)
downloadperlweeklychallenge-club-7917cf7c630338e3ec9c656e90108baa90bb0c25.tar.gz
perlweeklychallenge-club-7917cf7c630338e3ec9c656e90108baa90bb0c25.tar.bz2
perlweeklychallenge-club-7917cf7c630338e3ec9c656e90108baa90bb0c25.zip
feat: add solutions for challenge 255 from BarrOff
Diffstat (limited to 'challenge-255/barroff/perl')
-rw-r--r--challenge-255/barroff/perl/ch-1.pl33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-255/barroff/perl/ch-1.pl b/challenge-255/barroff/perl/ch-1.pl
new file mode 100644
index 0000000000..18aa56e2a8
--- /dev/null
+++ b/challenge-255/barroff/perl/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+
+use v5.38;
+
+sub odd_character ( $s, $t ) {
+ my @sorted_s = sort( split( //, $s ) );
+ my @sorted_t = sort( split( //, $t ) );
+ for ( 0 .. @sorted_s - 1 ) {
+ if ( $sorted_s[$_] ne $sorted_t[$_] ) {
+ return $sorted_t[$_];
+ }
+ }
+ return $sorted_t[-1];
+}
+
+sub MAIN() {
+ if ( @ARGV > 1 ) {
+
+ #| Run on command line argument
+ say odd_character( $ARGV[1], $ARGV[2] );
+ }
+ else {
+ #| Run test cases
+ use Test2::V0 qw( is plan );
+ plan 3;
+
+ is odd_character( 'Perl', 'Peerl' ), 'e', 'works for "Perl"';
+ is odd_character( 'Weekly', 'Weeakly' ), 'a', 'works for "Weekly"';
+ is odd_character( 'Box', 'Boxy' ), 'y', 'works for "Box"';
+ }
+}
+
+MAIN();