diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2024-01-01 18:17:11 -0500 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2024-01-01 18:17:11 -0500 |
| commit | bef55b614c66df6a01ff4ca5f3e0c8559b541585 (patch) | |
| tree | 54b3772eb45ce0b6012a77cebdd0b852f308d4aa | |
| parent | 5f38c976cae9103ec02e413224d047d8b149956d (diff) | |
| download | perlweeklychallenge-club-bef55b614c66df6a01ff4ca5f3e0c8559b541585.tar.gz perlweeklychallenge-club-bef55b614c66df6a01ff4ca5f3e0c8559b541585.tar.bz2 perlweeklychallenge-club-bef55b614c66df6a01ff4ca5f3e0c8559b541585.zip | |
DAJ #250
| -rw-r--r-- | challenge-250/dave-jacoby/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-250/dave-jacoby/perl/ch-1.pl | 35 | ||||
| -rw-r--r-- | challenge-250/dave-jacoby/perl/ch-2.pl | 35 |
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; +} |
