aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-08-12 23:31:33 +0100
committerGitHub <noreply@github.com>2024-08-12 23:31:33 +0100
commit1649ae200d3a597c6e22e0fdb3c42fe6db974fa5 (patch)
treef4789b8d1685ac3984984a91741ce09ac771ee0e
parent37e6174ce5338a76a760c4a10e93b6daa503f1ec (diff)
parentb6320850400ab3d12e8be91f78a18415a14f7166 (diff)
downloadperlweeklychallenge-club-1649ae200d3a597c6e22e0fdb3c42fe6db974fa5.tar.gz
perlweeklychallenge-club-1649ae200d3a597c6e22e0fdb3c42fe6db974fa5.tar.bz2
perlweeklychallenge-club-1649ae200d3a597c6e22e0fdb3c42fe6db974fa5.zip
Merge pull request #10603 from jacoby/master
DAJ 282
-rw-r--r--challenge-282/dave-jacoby/perl/ch-1.pl38
-rw-r--r--challenge-282/dave-jacoby/perl/ch-2.pl29
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;
+}