diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-02-27 11:46:08 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-27 11:46:08 +0000 |
| commit | 5820b5c6bae41382621a3ca860723c681de8e576 (patch) | |
| tree | 1a605ab93945b10086ce13222cd12cc4f5652cdb | |
| parent | aabb5221f9e7f9f1e57a208765ac4bd83320fce5 (diff) | |
| parent | 8f42ed3b57f95766d8e01209153823355294890e (diff) | |
| download | perlweeklychallenge-club-5820b5c6bae41382621a3ca860723c681de8e576.tar.gz perlweeklychallenge-club-5820b5c6bae41382621a3ca860723c681de8e576.tar.bz2 perlweeklychallenge-club-5820b5c6bae41382621a3ca860723c681de8e576.zip | |
Merge pull request #9660 from rjt-pl/master
rjt week 258
| -rw-r--r-- | challenge-258/ryan-thompson/README.md | 12 | ||||
| -rw-r--r-- | challenge-258/ryan-thompson/perl/ch-1.pl | 5 | ||||
| -rw-r--r-- | challenge-258/ryan-thompson/perl/ch-2.pl | 10 | ||||
| -rw-r--r-- | challenge-258/ryan-thompson/raku/ch-1.raku | 3 | ||||
| -rw-r--r-- | challenge-258/ryan-thompson/raku/ch-2.raku | 5 |
5 files changed, 28 insertions, 7 deletions
diff --git a/challenge-258/ryan-thompson/README.md b/challenge-258/ryan-thompson/README.md index 66151b9345..b3303d62c9 100644 --- a/challenge-258/ryan-thompson/README.md +++ b/challenge-258/ryan-thompson/README.md @@ -1,19 +1,17 @@ # Ryan Thompson -## Week 171 Solutions +## Week 258 Solutions -### Task 1 › Odd Abundant Numbers +### Task 1 › Count Even Digits Number * [Perl](perl/ch-1.pl) - * [Perl](perl/ch-1a.pl) — Alternative implementations (see blog) * [Raku](raku/ch-1.raku) -### Task 2 › First Class Functions +### Task 2 › Sum of Values * [Perl](perl/ch-2.pl) * [Raku](raku/ch-2.raku) -## Blogs +## Blog - * [Odd Abundant Numbers](https://ry.ca/2022/06/odd-abundant-numbers/) - * [First Class Functions](https://ry.ca/2022/06/first-class-functions/) + * [Counting Digits and Summing Values](https://ry.ca/2024/02/pwc-258-counting-digits-and-summing-values/) diff --git a/challenge-258/ryan-thompson/perl/ch-1.pl b/challenge-258/ryan-thompson/perl/ch-1.pl new file mode 100644 index 0000000000..b471158f35 --- /dev/null +++ b/challenge-258/ryan-thompson/perl/ch-1.pl @@ -0,0 +1,5 @@ +# https://theweeklychallenge.org/blog/perl-weekly-challenge-258/ +# +# Ryan Thompson <rjt@cpan.org> + +sub even_re { ()= "@_" =~ /\b(\d\d)+\b/g } diff --git a/challenge-258/ryan-thompson/perl/ch-2.pl b/challenge-258/ryan-thompson/perl/ch-2.pl new file mode 100644 index 0000000000..aa69b9493a --- /dev/null +++ b/challenge-258/ryan-thompson/perl/ch-2.pl @@ -0,0 +1,10 @@ +# Ryan Thompson <rjt@cpan.org> + +use List::Util qw< sum >; + +sub sum_idx_bit_set { + my $k = pop; + sum map { $_[$_] } grep { $k == ( ()= sprintf('%b',$_) =~ /1/g ) } 0..$#_ +} + +print sum_idx_bit_set(2, 5, 9, 11, 3 => 1); diff --git a/challenge-258/ryan-thompson/raku/ch-1.raku b/challenge-258/ryan-thompson/raku/ch-1.raku new file mode 100644 index 0000000000..7a2b5758ac --- /dev/null +++ b/challenge-258/ryan-thompson/raku/ch-1.raku @@ -0,0 +1,3 @@ +# Ryan Thompson <rjt@cpan.org> + +sub even_re { +@_.grep(/^(\d\d)+$/) } diff --git a/challenge-258/ryan-thompson/raku/ch-2.raku b/challenge-258/ryan-thompson/raku/ch-2.raku new file mode 100644 index 0000000000..d6d389f411 --- /dev/null +++ b/challenge-258/ryan-thompson/raku/ch-2.raku @@ -0,0 +1,5 @@ +# Ryan Thompson <rjt@cpan.org> + +sub sum_idx_bit_set($k, @n) { + @n[ @n.keys.grep({ (TR:d/10/1/ with .base(2)) == $k }) ].sum +} |
