aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-190/dave-jacoby/perl/ch-1.pl22
-rw-r--r--challenge-190/dave-jacoby/perl/ch-2.pl43
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-190/dave-jacoby/perl/ch-1.pl b/challenge-190/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..9623b328ba
--- /dev/null
+++ b/challenge-190/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ fc say postderef signatures state };
+
+my @input = qw( Perl TPF PyThon raku);
+
+for my $input (@input) {
+ my $output = capital_detect( $input );
+ say <<"END";
+ Input: \$s = '$input'
+ Output: $output
+END
+}
+
+sub capital_detect ( $input ) {
+ return 1 if $input eq uc $input;
+ return 1 if $input eq lc $input;
+ return 1 if $input eq ucfirst lc $input;
+ return 0;
+}
diff --git a/challenge-190/dave-jacoby/perl/ch-2.pl b/challenge-190/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..f4a52f2e65
--- /dev/null
+++ b/challenge-190/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use List::Util qw{ uniq };
+
+my @alphabet = ( '_', 'A' .. 'Z' );
+my %n2a = map { $_ => $alphabet[$_] } 1 .. 26;
+
+my @input = sort { $a <=> $b } qw( 1115 127 919 212 202 2112 );
+for my $i (@input) {
+ my @list = decoded_list($i);
+ my $list = join ', ', @list;
+ say <<"END";
+ Input: \$s = $i
+ Output: $list
+END
+}
+
+sub decoded_list ( $input ) {
+ my @output;
+ my @list = _make_list($input);
+OUTER: for my $x (@list) {
+ my @x = grep { /\d/ } split /\D+/, $x;
+ for my $y (@x) { next OUTER if !$n2a{$y} }
+ push @output, join '', map { $n2a{$_} } @x;
+ }
+ return uniq sort @output;
+}
+
+sub _make_list ( $input, $string = '' ) {
+ if ( $input eq '' ) {
+ return ($string);
+ }
+ my $letter = substr( $input, 0, 1 );
+ substr( $input, 0, 1 ) = '';
+ my @output;
+ push @output, _make_list( $input, $string . $letter );
+ push @output, _make_list( $input, $string . ' ' . $letter );
+ return @output;
+}