diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2024-08-11 23:21:32 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2024-08-11 23:21:32 -0600 |
| commit | 5c5625d2bc6afcea705f91acf68b57f502c0f3ca (patch) | |
| tree | 4e9efe783bbd26f88b67a8777cf1bac42b2cdd3f /challenge-282 | |
| parent | 419a326807744bba437997c323b33875c75a65e4 (diff) | |
| download | perlweeklychallenge-club-5c5625d2bc6afcea705f91acf68b57f502c0f3ca.tar.gz perlweeklychallenge-club-5c5625d2bc6afcea705f91acf68b57f502c0f3ca.tar.bz2 perlweeklychallenge-club-5c5625d2bc6afcea705f91acf68b57f502c0f3ca.zip | |
Solve PWC282
Diffstat (limited to 'challenge-282')
| -rw-r--r-- | challenge-282/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-282/wlmb/perl/ch-1.pl | 18 | ||||
| -rwxr-xr-x | challenge-282/wlmb/perl/ch-2.pl | 17 |
3 files changed, 36 insertions, 0 deletions
diff --git a/challenge-282/wlmb/blog.txt b/challenge-282/wlmb/blog.txt new file mode 100644 index 0000000000..b569f64ef8 --- /dev/null +++ b/challenge-282/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/08/11/PWC282/ diff --git a/challenge-282/wlmb/perl/ch-1.pl b/challenge-282/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..9aa15f4494 --- /dev/null +++ b/challenge-282/wlmb/perl/ch-1.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +# Perl weekly challenge 282 +# Task 1: Good Integer +# +# See https://wlmb.github.io/2024/08/11/PWC282/#task-1-good-integer +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 N1 N2... + to find good integers within the numbers N1 N2... + FIN +ARG: for(@ARGV){ + my $arg=$_; + warn "Expected only digits: $_" unless /^\d+$/; + while(s/((.)\2\2(\2*))//){ + say("$arg -> $1"), next ARG unless $3; + } + say "$arg -> -1" +} diff --git a/challenge-282/wlmb/perl/ch-2.pl b/challenge-282/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..6d80a62e2b --- /dev/null +++ b/challenge-282/wlmb/perl/ch-2.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +# Perl weekly challenge 282 +# Task 2: Changing Keys +# +# See https://wlmb.github.io/2024/08/11/PWC282/#task-2-changing-keys +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 S1 S2... + to count how many key changes are required for each character in strings S1 S2... + FIN +for(@ARGV){ + warn("Expected alphabetical string: $_"), next unless /^[a-zA-Z]+$/; + my $arg=$_; + $_=lc; + s/(.)\1+/$1/g; + say "$arg -> ", length($_)-1 +} |
