diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2024-08-12 18:11:02 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2024-08-12 18:11:02 -0400 |
| commit | b6320850400ab3d12e8be91f78a18415a14f7166 (patch) | |
| tree | b452a99d6861f3871c852d16e61fdedbdef1bad9 /challenge-282 | |
| parent | 51834a29c71cd0c6af0120d0f57583b6cab94ee6 (diff) | |
| download | perlweeklychallenge-club-b6320850400ab3d12e8be91f78a18415a14f7166.tar.gz perlweeklychallenge-club-b6320850400ab3d12e8be91f78a18415a14f7166.tar.bz2 perlweeklychallenge-club-b6320850400ab3d12e8be91f78a18415a14f7166.zip | |
DAJ 282
Diffstat (limited to 'challenge-282')
| -rw-r--r-- | challenge-282/dave-jacoby/perl/ch-1.pl | 38 | ||||
| -rw-r--r-- | challenge-282/dave-jacoby/perl/ch-2.pl | 29 |
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-282/dave-jacoby/perl/ch-1.pl b/challenge-282/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..663a970d17 --- /dev/null +++ b/challenge-282/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,38 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ postderef say signatures state }; + +use List::Util qw{ uniq }; + +my @examples = ( 12344456, 1233334, 10020003 ); + +for my $example (@examples) { + my $output = good_integer($example); + say <<"END"; + Input: \@int = $example + Output: $output +END +} + +sub good_integer ($input) { + my $good = ''; + my @input = split //, $input; + my $len = -1 + length $input; +OUTER: for my $i ( 0 .. $len ) { + if ( $i > 0 && $input[$i] eq $input[ $i - 1 ] ) { + next; + } + for my $j ( 1 .. $len ) { + my $k = $i + $j; + next if $k > $len; + my @split = @input[ $i .. $k ]; + my @digits = uniq sort @split; + next OUTER if scalar @digits > 1; + $good = join '', @split if scalar @split > 2; + } + } + return qq{"$good"} if length $good == 3; + return -1; +} diff --git a/challenge-282/dave-jacoby/perl/ch-2.pl b/challenge-282/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..ee38c2bc28 --- /dev/null +++ b/challenge-282/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ fc say postderef signatures state }; + +my @examples = ( # added a couple test entries + + qw{ pPeERrLl rRr GoO } +); + +for my $input (@examples) { + my $output = changing_keys($input); + say <<"END"; + Input: \$str = "$input" + Output: $output +END +} + +sub changing_keys ($input) { + my $c = 0; + my $len = -1 + length $input; + for my $i ( 1 .. $len ) { + my $l = fc substr $input, $i - 1, 1; + my $t = fc substr $input, $i, 1; + $c++ if $l ne $t; + } + return $c; +} |
