aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-12-05 00:10:05 +0000
committerGitHub <noreply@github.com>2022-12-05 00:10:05 +0000
commit800476499f50e4f381695298966e7125cdbf4e0d (patch)
tree7e5cee5d1f7487938825f28972f918f8e632c38e
parentb48b35cc8e76e6688cf8c68eb1a9af6f7e2fd23e (diff)
parentddd2b8d90010108ea70bf66310f32120bad79013 (diff)
downloadperlweeklychallenge-club-800476499f50e4f381695298966e7125cdbf4e0d.tar.gz
perlweeklychallenge-club-800476499f50e4f381695298966e7125cdbf4e0d.tar.bz2
perlweeklychallenge-club-800476499f50e4f381695298966e7125cdbf4e0d.zip
Merge pull request #7203 from tcheukueppo/pwc-193
Pwc 193
-rw-r--r--challenge-193/kueppo-wesley/Perl/ch-1.pl31
-rw-r--r--challenge-193/kueppo-wesley/Perl/ch-2.pl27
2 files changed, 58 insertions, 0 deletions
diff --git a/challenge-193/kueppo-wesley/Perl/ch-1.pl b/challenge-193/kueppo-wesley/Perl/ch-1.pl
new file mode 100644
index 0000000000..5156292c81
--- /dev/null
+++ b/challenge-193/kueppo-wesley/Perl/ch-1.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw/ state current_sub /;
+
+use Test::More;
+
+sub find_bins {
+ my ( $size, $partial ) = @_;
+ state $solution;
+
+ $partial = '', $solution = undef unless defined $partial;
+ if ( $size == 0 ) {
+ push @$solution, $partial;
+ }
+ else {
+ __SUB__->( $size - 1, '0' . $partial );
+ __SUB__->( $size - 1, '1' . $partial );
+ }
+
+ return $solution;
+}
+
+subtest 'find_bins' => sub {
+ is_deeply(find_bins(3), [ qw( 000 100 010 110 001 101 011 111 ) ], "works for 3?");
+ is_deeply(find_bins(2), [ qw( 00 10 01 11 ) ], "works for 2?");
+ is_deeply(find_bins(1), [ qw( 0 1 ) ], "works for 1?");
+};
+
+done_testing(1);
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);