diff options
| -rw-r--r-- | challenge-258/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-258/wlmb/perl/ch-1.pl | 13 | ||||
| -rwxr-xr-x | challenge-258/wlmb/perl/ch-2.pl | 16 |
3 files changed, 30 insertions, 0 deletions
diff --git a/challenge-258/wlmb/blog.txt b/challenge-258/wlmb/blog.txt new file mode 100644 index 0000000000..e14ee95eb1 --- /dev/null +++ b/challenge-258/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/02/26/PWC258/ diff --git a/challenge-258/wlmb/perl/ch-1.pl b/challenge-258/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..2b68642530 --- /dev/null +++ b/challenge-258/wlmb/perl/ch-1.pl @@ -0,0 +1,13 @@ +#!/usr/bin/env perl +# Perl weekly challenge 258 +# Task 1: Count Even Digits Number +# +# See https://wlmb.github.io/2024/02/26/PWC258/#task-1-count-even-digits-number +use v5.36; +use List::Util qw(all); +die <<~"FIN" unless @ARGV; + Usage: $0 N1 [N2...] + to count how many input numbers have an even number of digits. + FIN +die "Only digits allowed" unless all {/^\d+$/} @ARGV; +say "@ARGV -> ", 0+grep {(split "")%2==0}@ARGV; diff --git a/challenge-258/wlmb/perl/ch-2.pl b/challenge-258/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..7a7338d903 --- /dev/null +++ b/challenge-258/wlmb/perl/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +# Perl weekly challenge 258 +# Task 2: Sum of Values +# +# See https://wlmb.github.io/2024/02/26/PWC258/#task-2-sum-of-values +use v5.36; +use List::Util qw(sum0); +die <<~"FIN" unless @ARGV; + Usage: $0 K N0 [N1...] + to sum the values of Nm whose index m has K ones in its binary representation + FIN +my ($k,@int)=@ARGV; +# Convert to binary, add ones and compare to $k to filter indices +my @indices=grep {$k==sum0 split "", sprintf "%b",$_}0..@int-1; +my $result=sum0 @int[@indices]; +say "k=$k, ints=@int -> ", $result; |
