aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Bell_West <roger@firedrake.org>2024-08-04 09:20:41 +0100
committerRoger Bell_West <roger@firedrake.org>2024-08-04 09:20:41 +0100
commit22d323bb2fa927cce8d9e2d81bebc7e3b18d7a8b (patch)
tree597d944adc1fcff029cfb7b24fc1d3779fbe68ff
parentbd9c64bbea0318b67e02d309e65708c214a6ff15 (diff)
parent47a6a89dbac521d91d7e8742347faefaa74cca67 (diff)
downloadperlweeklychallenge-club-22d323bb2fa927cce8d9e2d81bebc7e3b18d7a8b.tar.gz
perlweeklychallenge-club-22d323bb2fa927cce8d9e2d81bebc7e3b18d7a8b.tar.bz2
perlweeklychallenge-club-22d323bb2fa927cce8d9e2d81bebc7e3b18d7a8b.zip
Merge remote-tracking branch 'upstream/master'
-rw-r--r--challenge-277/ryan-thompson/README.md10
-rw-r--r--challenge-277/ryan-thompson/blog.txt1
-rw-r--r--challenge-277/ryan-thompson/perl/ch-1.pl35
-rw-r--r--challenge-277/ryan-thompson/perl/ch-2.pl28
-rw-r--r--challenge-280/0rir/raku/ch-1.raku68
-rw-r--r--challenge-280/0rir/raku/ch-2.raku140
-rwxr-xr-xchallenge-280/alexander-karelas/perl/ch-2.pl16
-rw-r--r--challenge-280/bob-lied/README6
-rw-r--r--challenge-280/bob-lied/perl/ch-1.pl95
-rw-r--r--challenge-280/bob-lied/perl/ch-2.pl78
-rw-r--r--challenge-280/deadmarshal/blog.txt1
-rw-r--r--challenge-280/deadmarshal/java/Ch1.java17
-rw-r--r--challenge-280/deadmarshal/java/Ch2.java19
-rw-r--r--challenge-280/deadmarshal/modula-3/ch1/src/Ch1.m323
-rw-r--r--challenge-280/deadmarshal/modula-3/ch1/src/m3makefile5
-rw-r--r--challenge-280/deadmarshal/modula-3/ch2/src/Ch2.m327
-rw-r--r--challenge-280/deadmarshal/modula-3/ch2/src/m3makefile5
-rw-r--r--challenge-280/deadmarshal/perl/ch-1.pl12
-rw-r--r--challenge-280/deadmarshal/perl/ch-2.pl13
-rw-r--r--challenge-280/deadmarshal/raku/ch-1.raku11
-rw-r--r--challenge-280/deadmarshal/raku/ch-2.raku12
-rw-r--r--challenge-280/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-280/jaldhar-h-vyas/perl/ch-1.pl13
-rwxr-xr-xchallenge-280/jaldhar-h-vyas/perl/ch-2.sh3
-rwxr-xr-xchallenge-280/jaldhar-h-vyas/raku/ch-1.raku16
-rwxr-xr-xchallenge-280/jaldhar-h-vyas/raku/ch-2.sh3
-rw-r--r--challenge-280/jo-37/blog.txt1
-rwxr-xr-xchallenge-280/jo-37/perl/ch-1.pl74
-rwxr-xr-xchallenge-280/jo-37/perl/ch-2.pl64
-rw-r--r--challenge-280/kjetillll/perl/ch-1.pl11
-rw-r--r--challenge-280/kjetillll/perl/ch-2.pl11
-rw-r--r--challenge-280/laurent-rosenfeld/blog1.txt1
-rw-r--r--challenge-280/laurent-rosenfeld/perl/ch-2.pl16
-rw-r--r--challenge-280/laurent-rosenfeld/raku/ch-2.raku11
-rwxr-xr-xchallenge-280/nelo-tovar/bash/ch-1.sh33
-rw-r--r--challenge-280/nelo-tovar/perl/ch-1.pl35
-rw-r--r--challenge-280/nelo-tovar/perl/ch-2.pl30
-rw-r--r--challenge-280/packy-anderson/README.md2
-rw-r--r--challenge-280/packy-anderson/blog.txt1
-rwxr-xr-xchallenge-280/packy-anderson/elixir/ch-1.exs36
-rwxr-xr-xchallenge-280/packy-anderson/elixir/ch-2.exs24
-rwxr-xr-xchallenge-280/packy-anderson/perl/ch-1.pl30
-rwxr-xr-xchallenge-280/packy-anderson/perl/ch-2.pl25
-rwxr-xr-xchallenge-280/packy-anderson/python/ch-1.py27
-rwxr-xr-xchallenge-280/packy-anderson/python/ch-2.py21
-rwxr-xr-xchallenge-280/packy-anderson/raku/ch-1.raku30
-rwxr-xr-xchallenge-280/packy-anderson/raku/ch-2.raku24
-rw-r--r--challenge-280/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-280/peter-campbell-smith/perl/ch-1.pl32
-rwxr-xr-xchallenge-280/peter-campbell-smith/perl/ch-2.pl29
-rwxr-xr-xchallenge-280/peter-meszaros/tcl/ch-1.tcl56
-rwxr-xr-xchallenge-280/peter-meszaros/tcl/ch-2.tcl58
-rw-r--r--challenge-280/reinier-maliepaard/blog.txt1
-rw-r--r--challenge-280/reinier-maliepaard/perl/ch-1.pl33
-rw-r--r--challenge-280/reinier-maliepaard/perl/ch-2.pl29
-rw-r--r--challenge-280/steven-wilson/python/ch-1.py34
-rw-r--r--challenge-280/steven-wilson/python/ch-2.py29
-rwxr-xr-xchallenge-280/ulrich-rieke/haskell/ch-1.hs45
-rw-r--r--challenge-280/wambash/raku/ch-1.raku20
-rw-r--r--challenge-280/wambash/raku/ch-2.raku20
-rwxr-xr-xchallenge-280/wanderdoc/perl/ch-1.pl49
-rwxr-xr-xchallenge-280/wanderdoc/perl/ch-2.pl67
-rw-r--r--stats/pwc-challenge-277.json613
-rw-r--r--stats/pwc-current.json452
-rw-r--r--stats/pwc-language-breakdown-2019.json298
-rw-r--r--stats/pwc-language-breakdown-2020.json346
-rw-r--r--stats/pwc-language-breakdown-2021.json744
-rw-r--r--stats/pwc-language-breakdown-2022.json372
-rw-r--r--stats/pwc-language-breakdown-2023.json710
-rw-r--r--stats/pwc-language-breakdown-2024.json282
-rw-r--r--stats/pwc-language-breakdown-summary.json64
-rw-r--r--stats/pwc-leaders.json380
-rw-r--r--stats/pwc-summary-1-30.json46
-rw-r--r--stats/pwc-summary-121-150.json54
-rw-r--r--stats/pwc-summary-151-180.json104
-rw-r--r--stats/pwc-summary-181-210.json50
-rw-r--r--stats/pwc-summary-211-240.json56
-rw-r--r--stats/pwc-summary-241-270.json102
-rw-r--r--stats/pwc-summary-271-300.json36
-rw-r--r--stats/pwc-summary-301-330.json32
-rw-r--r--stats/pwc-summary-31-60.json52
-rw-r--r--stats/pwc-summary-61-90.json38
-rw-r--r--stats/pwc-summary-91-120.json42
-rw-r--r--stats/pwc-summary.json72
-rw-r--r--stats/pwc-yearly-language-summary.json112
85 files changed, 4285 insertions, 2440 deletions
diff --git a/challenge-277/ryan-thompson/README.md b/challenge-277/ryan-thompson/README.md
index 588de6d8b1..537f4295ce 100644
--- a/challenge-277/ryan-thompson/README.md
+++ b/challenge-277/ryan-thompson/README.md
@@ -1,17 +1,15 @@
# Ryan Thompson
-## Week 276 Solutions
+## Week 277 Solutions
-### Task 1 › Complete Day
+### Task 1 › Count Common
* [Perl](perl/ch-1.pl)
- * [Python](python/ch-1.py)
-### Task 2 › Maximum Frequency
+### Task 2 › Strong Pair
* [Perl](perl/ch-2.pl)
- * [Python](python/ch-2.py)
## Blog
- * [Maximum Frequency and now my Day is Complete](https://ry.ca/2024/07/pwc-276-complete-day-and-maximum-frequency/)
+ * [We make a Strong Pair](https://ry.ca/2024/07/pwc-277-strong-pair-counting-common/)
diff --git a/challenge-277/ryan-thompson/blog.txt b/challenge-277/ryan-thompson/blog.txt
new file mode 100644
index 0000000000..01ded8abc3
--- /dev/null
+++ b/challenge-277/ryan-thompson/blog.txt
@@ -0,0 +1 @@
+https://ry.ca/2024/07/pwc-277-strong-pair-counting-common/
diff --git a/challenge-277/ryan-thompson/perl/ch-1.pl b/challenge-277/ryan-thompson/perl/ch-1.pl
new file mode 100644
index 0000000000..9446abbad0
--- /dev/null
+++ b/challenge-277/ryan-thompson/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+#
+# ch-1.pl - Count Common
+#
+# Count of words that appears in both arrays exactly once
+# My version supports an arbitrary number of arrays, instead of just two.
+# Modifying or wrapping it to limit it to two would be trivial.
+# Does NOT sort results by default. This is a minor optimization.
+# Sort if you need stable results.
+#
+# See blog post for more information:
+# https://ry.ca/2024/07/pwc-277-strong-pair-counting-common/
+#
+# 2024 Ryan Thompson <rjt@cpan.org>
+
+use 5.010;
+use warnings;
+use strict;
+use Carp;
+use List::Util qw< all >;
+no warnings 'uninitialized';
+
+sub count_common {
+ 'ARRAY' ne ref and croak 'Arguments must be ARRAY refs' for @_; # VAL
+ my @once; # $once[$idx]{word} = # True if 'word' appears once in $_[$idx]
+
+ for my $i (keys @_) {
+ my %freq; $freq{$_}++ for @{ $_[$i] };
+ $once[$i]{$_} = 1 for grep { $freq{$_} == 1 } keys %freq;
+ }
+
+ grep { my $w = $_; all { $_->{$w} } @once } keys %{$once[0]}
+}
+
+1;
diff --git a/challenge-277/ryan-thompson/perl/ch-2.pl b/challenge-277/ryan-thompson/perl/ch-2.pl
new file mode 100644
index 0000000000..1e7daecc1f
--- /dev/null
+++ b/challenge-277/ryan-thompson/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+#
+# ch-2.pl - Strong Pair
+#
+# Return the count of all strong pairs in the given array
+# A pair of integers is strong if 0 < | x - y | < min(x,y)
+#
+# See blog post for more information:
+# https://ry.ca/2024/07/pwc-277-strong-pair-counting-common/
+#
+# 2024 Ryan Thompson <rjt@cpan.org>
+
+use 5.010;
+use warnings;
+use strict;
+use Carp;
+use List::Util qw< uniq min >;
+no warnings 'uninitialized';
+
+sub strong_pair {
+ ref || $_ !~ /^\-?\d+$/ and croak 'Arguments must be integers' for @_;
+ my @i = uniq sort { $a <=> $b } @_;
+
+ grep { my ($x,$y) = @$_; $x < $y and $y < 2*$x }
+ map { my $i = $_; map { [ @_[$i,$_] ] } $i+1..$#i } 0..$#i
+}
+
+1;
diff --git a/challenge-280/0rir/raku/ch-1.raku b/challenge-280/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..be79984f82
--- /dev/null
+++ b/challenge-280/0rir/raku/ch-1.raku
@@ -0,0 +1,68 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+280 1: Twice Appearance Submitted by: Mohammad Sajid Anwar
+You are given a string, $str, containing lowercase English letters only.
+
+Write a script to print the first letter that appears twice.
+
+Example 1
+Input: $str = "acbddbca"
+Output: "d"
+Example 2
+Input: $str = "abccd"
+Output: "c"
+Example 3
+Input: $str = "abcdabbb"
+Output: "a"
+=end comment
+
+my @Test =
+ # $in $exp
+ "acbddbca", "d",
+ "abccd", "c",
+ "abcdabbb", "a",
+ "abcdefgh", Str,
+ "", Str,
+;
+my @Mix =
+ "abcdefghiFi", 'f',
+;
+plan @Test * 1.5 + @Mix;
+
+multi task( Str:D $in, Bool:D :$case-force! ) { task( $in.lc); }
+multi task( Str:D $in, Bool:D :$case-ck! ) {
+ die qq{ERROR: "$in" is not lowercase.} if $in ne $in.lc;
+ task( $in);
+}
+multi task( Str:D $in --> Str ) {
+ my $s = ().SetHash;
+ my $e = $s.elems;
+ for 0..$in.chars -> \i {
+ my $c = $in.substr( i, 1);
+ $s.set: $c;
+ return $c if $s.elems == $e;
+ ++$e ;
+ }
+ Str;
+}
+
+for @Test -> $in, $exp {
+ is task($in), $exp, ($exp // "(Str)") ~ " <- $in";
+ is task($in, :case-ck),
+ $exp, ":case-ck " ~ ($exp // "(Str)") ~ " <- $in";
+ is task($in, :case-force),
+ $exp, ":case-force " ~ ($exp // "(Str)") ~ " <- $in";
+}
+for @Mix -> $in, $exp {
+ dies-ok { task($in, :case-ck)}, ":case-ck dies <- $in";
+ is task($in, :case-force), $exp, ":case-force $exp <- $in";
+}
+done-testing;
+
+my $str = 'abcdefghijklmnopqrstuvwxyzs';
+say qq{\nInput: \$str = "$str"\nOutput: "&task($str)"};
+
diff --git a/challenge-280/0rir/raku/ch-2.raku b/challenge-280/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..c60a29bdcc
--- /dev/null
+++ b/challenge-280/0rir/raku/ch-2.raku
@@ -0,0 +1,140 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+Task 2: Count Asterisks
+Submitted by: Mohammad Sajid Anwar
+ REPHASED
+Given a string, $str, where two consecutive vertical bars group the chars
+between them; a bar can only pair with one or none other bar.
+Return the number of asterisks, *, which are not within such pairs.
+
+Example 1
+Input: $str = "p|*e*rl|w**e|*ekly|"
+Ouput: 2
+
+The characters we are looking here are "p" and "w**e".
+Example 2
+Input: $str = "perl"
+Ouput: 0
+Example 3
+Input: $str = "th|ewe|e**|k|l***ych|alleng|e"
+Ouput: 5
+
+The characters we are looking here are "th", "e**", "l***ych" and "e".
+=end comment
+
+my @Test =
+ # str exp
+ '', 0,
+ # ^ sep $
+ '|', 0,
+ # ^ outer $
+ 'x', 0,
+ '*', 1,
+ # ^ outer sep $
+ '*|', 1,
+ 'x|', 0,
+ # ^ sep outer $
+ '|*', 1,
+ '|x', 0,
+
+ # ^ outer sep outer $
+ '*|*', 2,
+
+ # ^ outer pair …
+ 'x||', 0,
+ 'x|i|', 0,
+ 'x|*|', 0,
+ '*||', 1,
+ '*|i|', 1,
+ '*|*|', 1,
+ '*|*||i|', 1,
+ 'x||x', 0,
+ 'x|i|x', 0,
+ 'x|*|x', 0,
+ 'x|*||i|x', 0,
+ '*||x', 1,
+ '*|i|x', 1,
+ '*|*|x', 1,
+ '*|*||i|x', 1,
+ 'x|*||i|', 0,
+ '*|*|*', 2,
+ '*|a|a', 1,
+ 'a|*|a', 0,
+ 'a|a|*', 1,
+ '*|*|x', 1,
+
+ # ^ pair …
+ '||', 0,
+ '|i|', 0,
+ '|*|', 0,
+
+ '||x', 0,
+ '|i|x', 0,
+ '|*|x', 0,
+ '|*||i|', 0,
+ '|*|*', 1,
+ '|*||i|x', 0,
+
+ # ^ pair … trailing sep
+ 'p|*e*rl|w**e|*ekly|*x*|', 4,
+ 'p|*e*rl|w**e|*ekly||', 2,
+ 'th|ewe|e**|k|l***ych|alleng|e|', 5,
+ 'th|ewe|e**|k|l***ych|alleng|*e|', 6,
+ 'th|ewe|e**|k|l***ych|alleng|*e|e', 6,
+ 'th|ewe|e**|k|l***ych|alleng|*e|*', 7,
+
+ # given
+ 'p|*e*rl|w**e|*ekly|', 2,
+ 'perl', 0,
+ 'th|ewe|e**|k|l***ych|alleng|e', 5,
+;
+plan @Test ÷ 2;
+
+#use Grammar::Tracer;
+
+grammar pair-exclus {
+ rule TOP { # The idea is to never re-traverse an <outer> …
+ ^ [ # shorts
+ || $
+ || <sep> $
+ || <sep> <outer> $
+ || <outer> [ $ || <sep> $ || <sep> <outer> ] $
+ ]
+ ||
+ [
+ || [ <pair>+ <outer>? ]+ [ <sep> <outer>? ]? $
+ || <outer> [ <pair>+ <outer>? ]+ [ <sep> <outer>? ]? $
+ ]
+ }
+ rule pair { <sep> <inner>? <sep> }
+ token inner { <-[ | ]>+ }
+ token outer { <-[ | ]>+ } # Rename/alias text w/o capture?
+ rule text { <-[ | ]>+ } # How to use named regex here?
+ token sep { '|' }
+}
+
+class Count {
+ # … so that no containing rule needs to filter <outer>.made
+ my $char-sot = '*';
+ method TOP($/) { make sum $<outer>».made }
+ method outer($/) { make $/.comb.grep( $char-sot ).elems }
+}
+
+multi task( Any:U $data ) { die 'No match' }
+multi task( $data -->Int) {
+ my $match = pair-exclus.parse( $data, :actions(Count.new ));
+ $match.made
+}
+for @Test -> $data, $exp {
+ is task( $data), $exp, "$exp <~∘ $data";
+}
+
+done-testing;
+
+my $str = 'th|ewe|e**|k|l***ych|alleng|*e|';
+
+say "\nInput: \$str = $str.raku()\nOutput: &task( $str)"
diff --git a/challenge-280/alexander-karelas/perl/ch-2.pl b/challenge-280/alexander-karelas/perl/ch-2.pl
new file mode 100755
index 0000000000..2788ae1f71
--- /dev/null
+++ b/challenge-280/alexander-karelas/perl/ch-2.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+
+use v5.40;
+
+use Test::More;
+
+sub do_it ($str) {
+ $str =~ s/\|.*?\|//sg;
+ return scalar(() = $str =~ /\*/g);
+}
+
+is do_it("p|*e*rl|w**e|*ekly|"), 2, 'Example 1';
+is do_it("perl"), 0, 'Example 2';
+is do_it("th|ewe|e**|k|l***ych|alleng|e"), 5, 'Example 3';
+
+done_testing;
diff --git a/challenge-280/bob-lied/README b/challenge-280/bob-lied/README
index c57c6cd9ae..ad25c661d8 100644
--- a/challenge-280/bob-lied/README
+++ b/challenge-280/bob-lied/README
@@ -1,4 +1,4 @@
-Solutions to weekly challenge 279 by Bob Lied
+Solutions to weekly challenge 280 by Bob Lied
-https://perlweeklychallenge.org/blog/perl-weekly-challenge-279/
-https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-279/bob-lied
+https://perlweeklychallenge.org/blog/perl-weekly-challenge-280/
+https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge