diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-05-20 09:14:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-20 09:14:00 +0100 |
| commit | 695a0fa6c7e38feaa49871cf8d9e7a0e4b935ef2 (patch) | |
| tree | 6526998e28d5bf5f6a0365d1ac383c9398b49534 /challenge-322 | |
| parent | 2e6324aef830bfa6293daf2b0c921a659af4fe21 (diff) | |
| parent | f2d24f326f6f2fe80abd077de489f47eae549ca3 (diff) | |
| download | perlweeklychallenge-club-695a0fa6c7e38feaa49871cf8d9e7a0e4b935ef2.tar.gz perlweeklychallenge-club-695a0fa6c7e38feaa49871cf8d9e7a0e4b935ef2.tar.bz2 perlweeklychallenge-club-695a0fa6c7e38feaa49871cf8d9e7a0e4b935ef2.zip | |
Merge pull request #12053 from wlmb/challenges
Solve PWC322
Diffstat (limited to 'challenge-322')
| -rw-r--r-- | challenge-322/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-322/wlmb/perl/ch-1.pl | 20 | ||||
| -rwxr-xr-x | challenge-322/wlmb/perl/ch-1b.pl | 19 | ||||
| -rwxr-xr-x | challenge-322/wlmb/perl/ch-2.pl | 15 |
4 files changed, 55 insertions, 0 deletions
diff --git a/challenge-322/wlmb/blog.txt b/challenge-322/wlmb/blog.txt new file mode 100644 index 0000000000..fa97454e49 --- /dev/null +++ b/challenge-322/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2025/05/19/PWC322/ diff --git a/challenge-322/wlmb/perl/ch-1.pl b/challenge-322/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..863511df78 --- /dev/null +++ b/challenge-322/wlmb/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +# Perl weekly challenge 322 +# Task 1: String Format +# +# See https://wlmb.github.io/2025/05/19/PWC322/#task-1-string-format +use v5.36; +die <<~"FIN" unless @ARGV and @ARGV%2==0; + Usage: $0 S1 I1 S2 I2... + to edit string Sn making dahsed joined substrings of size not larger than In + by removing dashes from the original string. + FIN +for my($string, $size)(@ARGV){ + my $processing=""; + my @edited; + for(reverse split "-",$string){ + unshift(@edited, $processing), $processing="" if(length($processing)+length)>$size; + $processing = $_.$processing; + } + say "$string, $size -> ", join "-", $processing, @edited; +} diff --git a/challenge-322/wlmb/perl/ch-1b.pl b/challenge-322/wlmb/perl/ch-1b.pl new file mode 100755 index 0000000000..c76911faba --- /dev/null +++ b/challenge-322/wlmb/perl/ch-1b.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +# Perl weekly challenge 322 +# Task 1: String Format +# +# See https://wlmb.github.io/2025/05/19/PWC322/#task-1-string-format +use v5.36; +die <<~"FIN" unless @ARGV and @ARGV%2==0; + Usage: $0 S1 I1 S2 I2... + to edit string Sn making dashed joined substrings of size In + ignoring any dashes in the original string. + FIN +for my($string, $size)(@ARGV){ + my $reversed=reverse $string; # reverse + $reversed=~tr/-//d; # remove all dashes + $reversed=~s/(.{$size})/$1-/g; # add a dash every three chars + $reversed=~s/-$//; # remove final dash if any + my $out = reverse $reversed; + say"$string, size -> $out" +} diff --git a/challenge-322/wlmb/perl/ch-2.pl b/challenge-322/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..f53115ba56 --- /dev/null +++ b/challenge-322/wlmb/perl/ch-2.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# Perl weekly challenge 322 +# Task 2: Rank Array +# +# See https://wlmb.github.io/2025/05/19/PWC322/#task-2-rank-array +use v5.36; +use List::Util qw(uniq); +die <<~"FIN" unless @ARGV; + Usage: $0 N1 N2... + to find the ranks Ri of the numbers Ni + FIN +my %rank; +my $current=0; +$rank{$_}=++$current for sort {$a<=>$b} uniq @ARGV; +say "@ARGV -> @rank{@ARGV}"; |
