diff options
| -rw-r--r-- | challenge-197/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-197/wlmb/perl/ch-1.pl | 12 | ||||
| -rwxr-xr-x | challenge-197/wlmb/perl/ch-2.pl | 18 |
3 files changed, 31 insertions, 0 deletions
diff --git a/challenge-197/wlmb/blog.txt b/challenge-197/wlmb/blog.txt new file mode 100644 index 0000000000..24b7dbfd79 --- /dev/null +++ b/challenge-197/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2022/12/26/PWC197/ diff --git a/challenge-197/wlmb/perl/ch-1.pl b/challenge-197/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..5eff7453c7 --- /dev/null +++ b/challenge-197/wlmb/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/usr/bin/env perl +# Perl weekly challenge 197 +# Task 1: Move Zero +# +# See https://wlmb.github.io/2022/12/26/PWC197/#task-1-move-zero +use v5.36; +say(<<~"FIN"), exit unless @ARGV; + Usage: $0 N1 [N2...] + to move all zeroes among the numbers N1, N2... towards the right, + keeping the order of the rest. + FIN +say join " ", @ARGV, "->", sort {$a?$b?0:-1:1} @ARGV; diff --git a/challenge-197/wlmb/perl/ch-2.pl b/challenge-197/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..9c788743dd --- /dev/null +++ b/challenge-197/wlmb/perl/ch-2.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +# Perl weekly challenge 197 +# Task 2: Wiggle Sort +# +# See https://wlmb.github.io/2022/12/26/PWC197/#task-2-wiggle-sort +use v5.36; +use List::MoreUtils qw(any pairwise slide); +say(<<~"FIN"), exit unless @ARGV; + Usage: $0 N1 [N2...] + to wiggle sort the numbers N1 N2... + FIN +my @high=sort {$a <=> $b} @ARGV; +my @low=reverse splice @high, 0, (@high+1)/2; +@high=reverse @high; +my $prev; +my @out = grep {defined $_} pairwise {($a, $b)} @low, @high; +my $failed=any {$_} slide {$a == $b} @out; +say join " ", @ARGV, "->", $failed?"No solution":@out; |
