aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKUEPPO <tcheukueppo@tutanota.com>2022-12-04 21:51:16 +0100
committerGitHub <noreply@github.com>2022-12-04 21:51:16 +0100
commitddd2b8d90010108ea70bf66310f32120bad79013 (patch)
treea7cedf27d452d5f8c90b82cc1942147ff576b8bf
parent9b472e693d91d27d71d7c9a05bc6cb616b6043e4 (diff)
downloadperlweeklychallenge-club-ddd2b8d90010108ea70bf66310f32120bad79013.tar.gz
perlweeklychallenge-club-ddd2b8d90010108ea70bf66310f32120bad79013.tar.bz2
perlweeklychallenge-club-ddd2b8d90010108ea70bf66310f32120bad79013.zip
ch-2.pl
-rw-r--r--challenge-193/kueppo-wesley/Perl/ch-2.pl27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-193/kueppo-wesley/Perl/ch-2.pl b/challenge-193/kueppo-wesley/Perl/ch-2.pl
new file mode 100644
index 0000000000..a110c4bf3c
--- /dev/null
+++ b/challenge-193/kueppo-wesley/Perl/ch-2.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw/ state say /;
+
+use Test::More;
+
+sub find_odd_string {
+ state %mapper = map { ( 'a' .. 'z' )[$_] => $_ } 0 .. 25;
+
+ for my $string (@_) {
+ my @mapped = map { $mapper{$_} } split //, $string;
+ my @translated = map { $mapped[ $_ + 1 ] - $mapped[$_] } 0 .. $#mapped - 1;
+
+ return @translated if grep { $_ < 0 } @translated;
+ }
+}
+
+my %test_data = (
+ expected => [ [ 3, -1 ], [ 13, -13 ] ],
+ samples => [ [qw(adc wzy abc)], [qw(aaa bob ccc ddd)] ],
+);
+
+is_deeply( [ map { [ find_odd_string(@$_) ] } $test_data{samples}->@* ], $test_data{expected}, "did you find odd strings?" );
+
+done_testing(1);