diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-05-06 22:30:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-06 22:30:25 +0100 |
| commit | b0732d76f929b80e0fa2329bec97245b9a5b2522 (patch) | |
| tree | 34c977ddf976dbddeee0eef99710b433edf1b265 | |
| parent | b3401b0678dca36fea1f93050638b0164bb7f7a6 (diff) | |
| parent | 727f52061759d083a4ecba02a95e0db4fcc5dbbc (diff) | |
| download | perlweeklychallenge-club-b0732d76f929b80e0fa2329bec97245b9a5b2522.tar.gz perlweeklychallenge-club-b0732d76f929b80e0fa2329bec97245b9a5b2522.tar.bz2 perlweeklychallenge-club-b0732d76f929b80e0fa2329bec97245b9a5b2522.zip | |
Merge pull request #10050 from wlmb/challenges
Solve PWC268
| -rw-r--r-- | challenge-268/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-268/wlmb/perl/ch-1.pl | 16 | ||||
| -rwxr-xr-x | challenge-268/wlmb/perl/ch-2.pl | 17 |
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-268/wlmb/blog.txt b/challenge-268/wlmb/blog.txt new file mode 100644 index 0000000000..3ea74b1f37 --- /dev/null +++ b/challenge-268/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/05/06/PWC268/ diff --git a/challenge-268/wlmb/perl/ch-1.pl b/challenge-268/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..62f723eb20 --- /dev/null +++ b/challenge-268/wlmb/perl/ch-1.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +# Perl weekly challenge 268 +# Task 1: Magic Number +# +# See https://wlmb.github.io/2024/05/06/PWC268/#task-1-magic-number +use v5.36; +use PDL; +die <<~"FIN" unless @ARGV==2; + Usage: $0 X Y + where X is "[x1 x2...]" and Y=[y1 y2...] + to find the magic number M which added to the elements + of X yields the elements of Y + FIN +my ($x,$y)=map{pdl $_}@ARGV; +my (undef, $values)=($y->qsort-$x->qsort)->rle; +say "@ARGV -> ", $values->dim(0)==1?$values:"None" diff --git a/challenge-268/wlmb/perl/ch-2.pl b/challenge-268/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..7f0fac4262 --- /dev/null +++ b/challenge-268/wlmb/perl/ch-2.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +# Perl weekly challenge 268 +# Task 2: Number Game +# +# See https://wlmb.github.io/2024/05/06/PWC268/#task-2-number-game +use v5.36; +use experimental qw(for_list); +die <<~"FIN" unless @ARGV and @ARGV%2==0; + Usage: $0 N1 N2... N2m + to print array even sized array N1..N2m in zig-zag order + (decreasing pairs of increasing value) + FIN +my @result; +for my($x, $y)(sort {$a<=>$b} @ARGV){ + push @result, sort{$b<=>$a}($x,$y) +} +say "@ARGV -> @result"; |
