aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-02 11:14:14 +0000
committerGitHub <noreply@github.com>2024-01-02 11:14:14 +0000
commitca089255029dd07a23bc0f70110a774a3be01712 (patch)
tree54b3772eb45ce0b6012a77cebdd0b852f308d4aa
parent5f38c976cae9103ec02e413224d047d8b149956d (diff)
parentbef55b614c66df6a01ff4ca5f3e0c8559b541585 (diff)
downloadperlweeklychallenge-club-ca089255029dd07a23bc0f70110a774a3be01712.tar.gz
perlweeklychallenge-club-ca089255029dd07a23bc0f70110a774a3be01712.tar.bz2
perlweeklychallenge-club-ca089255029dd07a23bc0f70110a774a3be01712.zip
Merge pull request #9333 from jacoby/master
DAJ #250 - Leaping from Tree to Tree!
-rw-r--r--challenge-250/dave-jacoby/blog.txt1
-rw-r--r--challenge-250/dave-jacoby/perl/ch-1.pl35
-rw-r--r--challenge-250/dave-jacoby/perl/ch-2.pl35
3 files changed, 71 insertions, 0 deletions
diff --git a/challenge-250/dave-jacoby/blog.txt b/challenge-250/dave-jacoby/blog.txt
new file mode 100644
index 0000000000..3726a31806
--- /dev/null
+++ b/challenge-250/dave-jacoby/blog.txt
@@ -0,0 +1 @@
+https://jacoby.github.io/2024/01/01/leaping-from-tree-to-tree-as-they-float-down-the-mighty-rivers-of-british-columbia-weekly-challenge-250.html
diff --git a/challenge-250/dave-jacoby/perl/ch-1.pl b/challenge-250/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..15b5614127
--- /dev/null
+++ b/challenge-250/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use List::Util qw{ min };
+
+my @examples = (
+
+ [ 0, 1, 2 ],
+ [ 4, 3, 2, 1 ],
+ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 ],
+ [ 7, 7, 7, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 ],
+);
+
+for my $example (@examples) {
+ my $input = join ', ', $example->@*;
+ my $output = smallest_index( $example->@* );
+
+ say <<~"END";
+ Input: \$ints = ($input)
+ Output: $output
+ END
+}
+
+sub smallest_index (@input) {
+ my @output;
+ for my $i ( 0 .. -1 + scalar @input ) {
+ my $j = $i % 10;
+ push @output, $i if $input[$i] == $j;
+ }
+ return min @output if scalar @output;
+ return -1;
+}
diff --git a/challenge-250/dave-jacoby/perl/ch-2.pl b/challenge-250/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..1526412d61
--- /dev/null
+++ b/challenge-250/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use List::Util qw{ max };
+
+my @examples = (
+
+ [ "perl", "2", "000", "python", "r4ku" ],
+ [ "001", "1", "000", "0001" ],
+);
+
+for my $e (@examples) {
+ my $input = join ', ', map {qq{"$_"}} $e->@*;
+ my $output = alphanumeric_string_value( $e->@* );
+
+ say <<~"END";
+ Input: \@alphanumstr = ($input)
+ Output: $output
+ END
+}
+
+sub alphanumeric_string_value (@array) {
+ my @output;
+ for my $s (@array) {
+ no warnings;
+ my $n = 0;
+ if ( $s =~ /\d/ ) { $n = 0 + $s; }
+ else { $n = length $s; }
+ push @output, $n;
+ }
+ return max @output;
+}