From ddd2b8d90010108ea70bf66310f32120bad79013 Mon Sep 17 00:00:00 2001 From: KUEPPO Date: Sun, 4 Dec 2022 21:51:16 +0100 Subject: ch-2.pl --- challenge-193/kueppo-wesley/Perl/ch-2.pl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-193/kueppo-wesley/Perl/ch-2.pl 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); -- cgit