aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Neleigh <87619159+mattneleigh@users.noreply.github.com>2024-06-05 13:04:21 -0400
committerGitHub <noreply@github.com>2024-06-05 13:04:21 -0400
commitb7ddc0df59586129822cd79732dee50ddabbf18c (patch)
treee78636a66f5b729b049459837b524e701dc22082
parent74e6d81b2e785bd2f7dd4398ea5e2733618ac4b3 (diff)
parent7aeb2014a04d815bc006a3c337b73426a10ea591 (diff)
downloadperlweeklychallenge-club-b7ddc0df59586129822cd79732dee50ddabbf18c.tar.gz
perlweeklychallenge-club-b7ddc0df59586129822cd79732dee50ddabbf18c.tar.bz2
perlweeklychallenge-club-b7ddc0df59586129822cd79732dee50ddabbf18c.zip
Merge branch 'manwar:master' into pwc272
-rwxr-xr-xchallenge-270/e-choroba/perl/ch-2.pl51
-rwxr-xr-xchallenge-271/e-choroba/perl/ch-1.pl28
-rwxr-xr-xchallenge-271/e-choroba/perl/ch-2.pl21
-rw-r--r--challenge-272/chazzka/README1
-rw-r--r--challenge-272/chazzka/coconut/ch-2.coco6
-rw-r--r--challenge-272/chazzka/coconut/test/matching_test.coco14
-rw-r--r--challenge-272/dave-jacoby/perl/ch-1.pl24
-rw-r--r--challenge-272/dave-jacoby/perl/ch-2.pl25
-rw-r--r--challenge-272/deadmarshal/blog.txt1
-rw-r--r--challenge-272/deadmarshal/java/Ch1.java7
-rw-r--r--challenge-272/deadmarshal/java/Ch2.java16
-rw-r--r--challenge-272/deadmarshal/lua/ch-1.lua10
-rw-r--r--challenge-272/deadmarshal/lua/ch-2.lua16
-rw-r--r--challenge-272/deadmarshal/modula-3/ch1/src/Ch1.m330
-rw-r--r--challenge-272/deadmarshal/modula-3/ch1/src/m3makefile5
-rw-r--r--challenge-272/deadmarshal/modula-3/ch2/src/Ch2.m319
-rw-r--r--challenge-272/deadmarshal/modula-3/ch2/src/m3makefile5
-rw-r--r--challenge-272/deadmarshal/perl/ch-1.pl11
-rw-r--r--challenge-272/deadmarshal/perl/ch-2.pl14
-rw-r--r--challenge-272/deadmarshal/raku/ch-1.raku10
-rw-r--r--challenge-272/deadmarshal/raku/ch-2.raku16
-rwxr-xr-xchallenge-272/e-choroba/perl/ch-1.pl13
-rwxr-xr-xchallenge-272/e-choroba/perl/ch-2.pl22
-rwxr-xr-xchallenge-272/eric-cheung/python/ch-1.py7
-rwxr-xr-xchallenge-272/eric-cheung/python/ch-2.py9
-rwxr-xr-xchallenge-272/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-272/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-272/feng-chang/raku/test.raku23
-rw-r--r--challenge-272/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-272/jaldhar-h-vyas/perl/ch-1.sh3
-rwxr-xr-xchallenge-272/jaldhar-h-vyas/perl/ch-2.pl12
-rwxr-xr-xchallenge-272/jaldhar-h-vyas/raku/ch-1.sh3
-rwxr-xr-xchallenge-272/jaldhar-h-vyas/raku/ch-2.raku14
-rw-r--r--challenge-272/jeanluc2020/blog-1.txt1
-rw-r--r--challenge-272/jeanluc2020/blog-2.txt1
-rwxr-xr-xchallenge-272/jeanluc2020/perl/ch-1.pl47
-rwxr-xr-xchallenge-272/jeanluc2020/perl/ch-2.pl90
-rw-r--r--challenge-272/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-272/laurent-rosenfeld/perl/ch-1.pl14
-rw-r--r--challenge-272/laurent-rosenfeld/raku/ch-1.raku10
-rw-r--r--challenge-272/mark-anderson/raku/ch-1.raku5
-rw-r--r--challenge-272/mark-anderson/raku/ch-2.raku11
-rwxr-xr-xchallenge-272/perlboy1967/perl/ch-1.pl38
-rwxr-xr-xchallenge-272/perlboy1967/perl/ch-2.pl40
-rw-r--r--challenge-272/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-272/peter-campbell-smith/perl/ch-1.pl19
-rwxr-xr-xchallenge-272/peter-campbell-smith/perl/ch-2.pl23
-rwxr-xr-xchallenge-272/peter-meszaros/perl/ch-1.pl45
-rwxr-xr-xchallenge-272/peter-meszaros/perl/ch-2.pl93
-rw-r--r--challenge-272/steven-wilson/python/ch-1.py20
-rw-r--r--challenge-272/steven-wilson/python/ch-2.py26
-rwxr-xr-xchallenge-272/ulrich-rieke/cpp/ch-1.cpp15
-rwxr-xr-xchallenge-272/ulrich-rieke/cpp/ch-2.cpp26
-rwxr-xr-xchallenge-272/ulrich-rieke/haskell/ch-1.hs12
-rwxr-xr-xchallenge-272/ulrich-rieke/haskell/ch-2.hs8
-rwxr-xr-xchallenge-272/ulrich-rieke/perl/ch-1.pl10
-rwxr-xr-xchallenge-272/ulrich-rieke/perl/ch-2.pl16
-rwxr-xr-xchallenge-272/ulrich-rieke/raku/ch-1.raku6
-rwxr-xr-xchallenge-272/ulrich-rieke/raku/ch-2.raku11
-rwxr-xr-xchallenge-272/ulrich-rieke/rust/ch-1.rs10
-rwxr-xr-xchallenge-272/ulrich-rieke/rust/ch-2.rs21
-rw-r--r--challenge-272/wlmb/blog.txt1
-rwxr-xr-xchallenge-272/wlmb/perl/ch-1.pl17
-rwxr-xr-xchallenge-272/wlmb/perl/ch-2.pl19
-rw-r--r--challenge-272/zapwai/c/ch-1.c29
-rw-r--r--challenge-272/zapwai/c/ch-2.c24
-rw-r--r--challenge-272/zapwai/javascript/ch-1.js11
-rw-r--r--challenge-272/zapwai/javascript/ch-2.js19
-rw-r--r--challenge-272/zapwai/perl/ch-1.pl12
-rw-r--r--challenge-272/zapwai/perl/ch-2.pl15
-rw-r--r--challenge-272/zapwai/python/ch-1.py15
-rw-r--r--challenge-272/zapwai/python/ch-2.py18
-rw-r--r--challenge-272/zapwai/rust/ch-1.rs18
-rw-r--r--challenge-272/zapwai/rust/ch-2.rs21
-rw-r--r--guests.json1
-rw-r--r--stats/pwc-challenge-271.json646
-rw-r--r--stats/pwc-current.json600
-rw-r--r--stats/pwc-language-breakdown-summary.json62
-rw-r--r--stats/pwc-language-breakdown.json3707
-rw-r--r--stats/pwc-leaders.json828
-rw-r--r--stats/pwc-summary-1-30.json124
-rw-r--r--stats/pwc-summary-121-150.json120
-rw-r--r--stats/pwc-summary-151-180.json124
-rw-r--r--stats/pwc-summary-181-210.json26
-rw-r--r--stats/pwc-summary-211-240.json56
-rw-r--r--stats/pwc-summary-241-270.json110
-rw-r--r--stats/pwc-summary-271-300.json112
-rw-r--r--stats/pwc-summary-301-330.json48
-rw-r--r--stats/pwc-summary-31-60.json40
-rw-r--r--stats/pwc-summary-61-90.json34
-rw-r--r--stats/pwc-summary-91-120.json48
-rw-r--r--stats/pwc-summary.json724
92 files changed, 5139 insertions, 3557 deletions
diff --git a/challenge-270/e-choroba/perl/ch-2.pl b/challenge-270/e-choroba/perl/ch-2.pl
index 0632f5713e..9396cc80ff 100755
--- a/challenge-270/e-choroba/perl/ch-2.pl
+++ b/challenge-270/e-choroba/perl/ch-2.pl
@@ -3,7 +3,7 @@ use warnings;
use strict;
use experimental qw( signatures );
-sub distribute_elements($x, $y, $ints) {
+sub equalize_array($x, $y, $ints) {
my @agenda = ([0, [sort { $a <=> $b } @$ints]]);
my %seen;
while (1) {
@@ -14,9 +14,7 @@ sub distribute_elements($x, $y, $ints) {
my @e = sort { $a <=> $b }
$elements->[0] + 1, @$elements[1 .. $#$elements];
- $seen{"@e"} = $price + $x,
- push @agenda, [$price + $x, \@e] if ! exists $seen{"@e"}
- || $seen{"@e"} > $price + $x;
+ push @agenda, [$price + $x, \@e] unless $seen{"@e"}++;
if (@$elements > 2 && 2 * $x > $y) {
for my $i (1, $#$elements) {
@@ -26,10 +24,7 @@ sub distribute_elements($x, $y, $ints) {
&& $_ != $i,
0 .. $#$elements];
- $seen{"@e"} = $price + $y,
- push @agenda, [$price + $y, \@e]
- if ! exists $seen{"@e"}
- || $seen{"@e"} > $price + $y;
+ push @agenda, [$price + $y, \@e] unless $seen{"@e"}++;
}
}
@@ -39,27 +34,27 @@ sub distribute_elements($x, $y, $ints) {
use Test::More tests => 2 + 17;
-is distribute_elements(3, 2, [4, 1]), 9, 'Example 1';
-is distribute_elements(2, 1, [2, 3, 3, 3, 5]), 6, 'Example 2';
-
-is distribute_elements(3, 1, [1, 2, 2]), 2, '3 1 [1 2 2]';
-is distribute_elements(4, 1, [1, 2, 2, 2, 2]), 3, '4 1 [1 2 2 2 2]';
-is distribute_elements(20, 1, [1, 2, 3, 3]), 21, '20 1 [1 2 3 3]';
-is distribute_elements(20, 1, [1, 2, 4, 4]), 22, '20 1 [1 2 4 4]';
-is distribute_elements(1, 7, [2, 2, 3, 5]), 8, '1 7 [2 2 3 5]';
-is distribute_elements(7, 1, [2, 2, 3, 5]), 4, '7 1 [2 2 3 5]';
-is distribute_elements(2, 3, [1, 1, 5]), 12, '2 3 [1 1 5]';
-is distribute_elements(17, 1, [1, 9, 9]), 16, '17 1 [1 9 9]';
-is distribute_elements(8, 9, [6, 6, 4, 2]), 34, '8 9 [6 6 4 2]';
-is distribute_elements(6, 1, [2, 5, 5, 6]), 5, '6 1 [2 5 5 6]';
-is distribute_elements(9, 1, [1, 2, 3, 3, 7]), 12, '9 1 [1 2 3 3 7]';
-is distribute_elements(7, 3, [1, 4, 7, 7, 7]), 21, '7 3 [1 4 7 7 7]';
-is distribute_elements(9, 1, [7, 1, 1, 4, 8]), 12, '9 1 [7 1 1 4 8]';
-is distribute_elements(1, 1, [1, 4, 3, 4, 5, 4, 2, 3, 7]), 15,
+is equalize_array(3, 2, [4, 1]), 9, 'Example 1';
+is equalize_array(2, 1, [2, 3, 3, 3, 5]), 6, 'Example 2';
+
+is equalize_array(3, 1, [1, 2, 2]), 2, '3 1 [1 2 2]';
+is equalize_array(4, 1, [1, 2, 2, 2, 2]), 3, '4 1 [1 2 2 2 2]';
+is equalize_array(20, 1, [1, 2, 3, 3]), 21, '20 1 [1 2 3 3]';
+is equalize_array(20, 1, [1, 2, 4, 4]), 22, '20 1 [1 2 4 4]';
+is equalize_array(1, 7, [2, 2, 3, 5]), 8, '1 7 [2 2 3 5]';
+is equalize_array(7, 1, [2, 2, 3, 5]), 4, '7 1 [2 2 3 5]';
+is equalize_array(2, 3, [1, 1, 5]), 12, '2 3 [1 1 5]';
+is equalize_array(17, 1, [1, 9, 9]), 16, '17 1 [1 9 9]';
+is equalize_array(8, 9, [6, 6, 4, 2]), 34, '8 9 [6 6 4 2]';
+is equalize_array(6, 1, [2, 5, 5, 6]), 5, '6 1 [2 5 5 6]';
+is equalize_array(9, 1, [1, 2, 3, 3, 7]), 12, '9 1 [1 2 3 3 7]';
+is equalize_array(7, 3, [1, 4, 7, 7, 7]), 21, '7 3 [1 4 7 7 7]';
+is equalize_array(9, 1, [7, 1, 1, 4, 8]), 12, '9 1 [7 1 1 4 8]';
+is equalize_array(1, 1, [1, 4, 3, 4, 5, 4, 2, 3, 7]), 15,
'1 1 [1 4 3 4 5 4 2 3 7]';
-is distribute_elements(4, 1, [1, 4, 1, 2, 5, 7, 1, 5]), 15,
+is equalize_array(4, 1, [1, 4, 1, 2, 5, 7, 1, 5]), 15,
'4 1 [1 4 1 2 5 7 1 5]';
-is distribute_elements(6, 10, [2, 3, 5, 1, 2, 1, 1, 7]), 170,
+is equalize_array(6, 10, [2, 3, 5, 1, 2, 1, 1, 7]), 170,
'6 10 [2 3 5 1 2 1 1 7]';
-is distribute_elements(4, 4, [4, 4, 1, 7, 2, 7, 1, 1, 4]), 64,
+is equalize_array(4, 4, [4, 4, 1, 7, 2, 7, 1, 1, 4]), 64,
'4 4 [4 4 1 7 2 7 1 1 4]';
diff --git a/challenge-271/e-choroba/perl/ch-1.pl b/challenge-271/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..4e96f45bbc
--- /dev/null
+++ b/challenge-271/e-choroba/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use PDL;
+
+sub maximum_ones($matrix) {
+ my $p = pdl($matrix);
+ my $sum = $p->sumover;
+ my $max = $sum->max;
+ return ($sum == $max)->which->unpdl->[0] + 1
+}
+
+use Test2::V0 qw{ plan is }; # Conflict with PDL::float.
+plan(3 + 1);
+
+is maximum_ones([[0, 1], [1, 0]]), 1, 'Example 1';
+is maximum_ones([[0, 0, 0], [1, 0, 1]]), 2, 'Example 2';
+is maximum_ones([[0, 0], [1, 1], [0, 0]]), 2, 'Example 3';
+
+
+is maximum_ones([[0, 0, 0, 0],
+ [1, 1, 0, 1],
+ [0, 0, 1, 0],
+ [1, 0, 0, 0],
+ [0, 1, 1, 1]]),
+ 2, 'Example 4';
diff --git a/challenge-271/e-choroba/perl/ch-2.pl b/challenge-271/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..561be4b901
--- /dev/null
+++ b/challenge-271/e-choroba/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub sort_by_1_bits(@ints) {
+ map $_->[1],
+ sort { $a->[0] <=> $b->[0]
+ ||
+ $a->[1] <=> $b->[1]
+ } map [unpack('%32b*', pack 'N', $_), $_],
+ @ints
+}
+
+use Test2::V0;
+plan(2);
+
+is [sort_by_1_bits(0, 1, 2, 3, 4, 5, 6, 7, 8)], [0, 1, 2, 4, 8, 3, 5, 6, 7],
+ 'Example 1';
+is [sort_by_1_bits(1024, 512, 256, 128, 64)], [64, 128, 256, 512, 1024],
+ 'Example 2';
diff --git a/challenge-272/chazzka/README b/challenge-272/chazzka/README
new file mode 100644
index 0000000000..fd45943659
--- /dev/null
+++ b/challenge-272/chazzka/README
@@ -0,0 +1 @@
+Solution by chazzka
diff --git a/challenge-272/chazzka/coconut/ch-2.coco b/challenge-272/chazzka/coconut/ch-2.coco
new file mode 100644
index 0000000000..f66b849fdb
--- /dev/null
+++ b/challenge-272/chazzka/coconut/ch-2.coco
@@ -0,0 +1,6 @@
+def string_score(s, accum = 0):
+ match s:
+ case [_]:
+ return accum
+ case [head, sec] + tail:
+ return string_score([sec] + tail, accum + abs(ord(sec) - ord(head))) \ No newline at end of file
diff --git a/challenge-272/chazzka/coconut/test/matching_test.coco b/challenge-272/chazzka/coconut/test/matching_test.coco
new file mode 100644
index 0000000000..de3748ff84
--- /dev/null
+++ b/challenge-272/chazzka/coconut/test/matching_test.coco
@@ -0,0 +1,14 @@
+import unittest
+import importlib
+solution = importlib.import_module("ch-2")
+
+
+class TestStringMethods(unittest.TestCase):
+ def test_matcher(self):
+ solution.string_score("hello") |> self.assertEqual$(13)
+ solution.string_score("perl") |> self.assertEqual$(30)
+ solution.string_score("raku") |> self.assertEqual$(37)
+ solution.string_score("coconut") |> self.assertEqual$(45)
+
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file
diff --git a/challenge-272/dave-jacoby/perl/ch-1.pl b/challenge-272/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..abaa466aae
--- /dev/null
+++ b/challenge-272/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ bitwise fc postderef say signatures state };
+
+use List::Util qw{max};
+
+my @examples = (
+
+ "1.1.1.1", "255.101.1.0"
+);
+for my $example (@examples) {
+ my $output = defang_ipv4($example);
+ say <<"END";
+ Input: \$ip = "$example"
+ Output: "$output"
+END
+}
+
+sub defang_ipv4 ( $address ) {
+ $address =~ s/\./[.]/gmx;
+ return $address;
+}
diff --git a/challenge-272/dave-jacoby/perl/ch-2.pl b/challenge-272/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..79650b52d9
--- /dev/null
+++ b/challenge-272/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ fc say postderef signatures state };
+
+use List::Util qw{ sum0 };
+
+my @examples = (qw{ hello perl raku weekly linux Perl PERL });
+
+for my $example (@examples) {
+ my $output = string_score($example);
+
+ say <<"END";
+ Input: \$str = "$example"
+ Output: $output
+END
+}
+
+sub string_score ($str) {
+ my @str = split //, $str;
+ return sum0
+ map { abs ord( $str[$_] ) - ord( $str[ 1 + $_ ] ) }
+ 0 .. -2 + scalar @str;
+}
diff --git a/challenge-272/deadmarshal/blog.txt b/challenge-272/deadmarshal/blog.txt
new file mode 100644
index 0000000000..dbb200ed12
--- /dev/null
+++ b/challenge-272/deadmarshal/blog.txt
@@ -0,0 +1 @@
+https://deadmarshal.blogspot.com/2024/06/twc272.html
diff --git a/challenge-272/deadmarshal/java/Ch1.java b/challenge-272/deadmarshal/java/Ch1.java
new file mode 100644
index 0000000000..6f589b0407
--- /dev/null
+++ b/challenge-272/deadmarshal/java/Ch1.java
@@ -0,0 +1,7 @@
+public class Ch1 {
+ public static void main(String[] args) {
+ System.out.println("1.1.1.1".replaceAll("\\.", "[.]"));
+ System.out.println("255.101.1.0".replaceAll("\\.", "[.]"));
+ }
+}
+
diff --git a/challenge-272/deadmarshal/java/Ch2.java b/challenge-272/deadmarshal/java/Ch2.java
new file mode 100644
index 0000000000..91614ab462
--- /dev/null
+++ b/