aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Bell_West <roger@firedrake.org>2021-05-05 09:05:19 +0100
committerRoger Bell_West <roger@firedrake.org>2021-05-05 09:05:19 +0100
commit87b5ebe9e07771cbb70cc569305e5b360afeedc0 (patch)
tree59a3bde53ee1def36c71c3598ff700bee5cc1017
parentc09c5e0af6d4d188a8877f153db6174398031f5f (diff)
parent5e66b581b9649e5bf461bc28bd391d25589e9258 (diff)
downloadperlweeklychallenge-club-87b5ebe9e07771cbb70cc569305e5b360afeedc0.tar.gz
perlweeklychallenge-club-87b5ebe9e07771cbb70cc569305e5b360afeedc0.tar.bz2
perlweeklychallenge-club-87b5ebe9e07771cbb70cc569305e5b360afeedc0.zip
Merge remote-tracking branch 'upstream/master'
-rwxr-xr-xchallenge-062/jo-37/perl/ch-1.pl77
-rwxr-xr-xchallenge-062/jo-37/perl/ch-2.pl184
-rwxr-xr-xchallenge-104/feng-chang/raku/ch-1.raku12
-rwxr-xr-xchallenge-104/feng-chang/raku/ch-2.raku51
-rwxr-xr-xchallenge-109/feng-chang/raku/ch-1.raku2
-rwxr-xr-xchallenge-109/feng-chang/raku/ch-2.raku18
-rw-r--r--challenge-110/cheok-yin-fung/java/TransposeFile.java2
-rwxr-xr-xchallenge-110/e-choroba/perl/ch-1.pl29
-rwxr-xr-xchallenge-110/e-choroba/perl/ch-2.pl39
-rwxr-xr-xchallenge-110/feng-chang/raku/ch-1.raku16
-rwxr-xr-xchallenge-110/feng-chang/raku/ch-2.raku8
-rw-r--r--challenge-110/feng-chang/raku/ch-2.txt5
-rw-r--r--challenge-110/ryan-thompson/blog.txt1
-rw-r--r--challenge-110/ryan-thompson/blog1.txt1
-rw-r--r--challenge-111/abigail/README.md120
-rw-r--r--challenge-111/abigail/awk/ch-1.awk30
-rw-r--r--challenge-111/abigail/awk/ch-2.gawk33
-rw-r--r--challenge-111/abigail/bash/ch-1.sh29
-rw-r--r--challenge-111/abigail/bash/ch-2.sh30
-rw-r--r--challenge-111/abigail/c/ch-1.c49
-rw-r--r--challenge-111/abigail/c/ch-2.c60
-rw-r--r--challenge-111/abigail/lua/ch-1.lua33
-rw-r--r--challenge-111/abigail/lua/ch-2.lua25
-rw-r--r--challenge-111/abigail/node/ch-1.js37
-rw-r--r--challenge-111/abigail/node/ch-2.js23
-rw-r--r--challenge-111/abigail/perl/ch-1.pl50
-rw-r--r--challenge-111/abigail/perl/ch-2.pl57
-rw-r--r--challenge-111/abigail/python/ch-1.py31
-rw-r--r--challenge-111/abigail/python/ch-2.py35
-rw-r--r--challenge-111/abigail/ruby/ch-1.rb32
-rw-r--r--challenge-111/abigail/ruby/ch-2.rb34
-rw-r--r--challenge-111/abigail/t/ctest.ini21
-rw-r--r--challenge-111/abigail/t/input-1-17
-rw-r--r--challenge-111/abigail/t/input-1-27
-rw-r--r--challenge-111/abigail/t/input-1-310
-rw-r--r--challenge-111/abigail/t/input-2-10
-rw-r--r--challenge-111/abigail/t/input-2-20
-rw-r--r--challenge-111/abigail/t/input-2-30
-rw-r--r--challenge-111/abigail/t/output-1-1.exp2
-rw-r--r--challenge-111/abigail/t/output-1-2.exp2
-rw-r--r--challenge-111/abigail/t/output-1-3.exp5
-rw-r--r--challenge-111/abigail/t/output-2-1.exp1
-rw-r--r--challenge-111/abigail/t/output-2-2.exp1
-rw-r--r--challenge-111/abigail/t/output-2-3.exp1
-rw-r--r--challenge-111/cheok-yin-fung/perl/ch-1.pl35
-rw-r--r--challenge-111/cheok-yin-fung/perl/ch-2.pl51
-rw-r--r--challenge-111/dave-jacoby/blog.txt1
-rw-r--r--challenge-111/dave-jacoby/perl/ch-1.pl100
-rw-r--r--challenge-111/dave-jacoby/perl/ch-2.pl33
-rwxr-xr-xchallenge-111/e-choroba/perl/ch-1.pl72
-rwxr-xr-xchallenge-111/e-choroba/perl/ch-2.pl31
-rwxr-xr-xchallenge-111/feng-chang/raku/ch-1.raku19
-rw-r--r--challenge-111/feng-chang/raku/ch-1.txt5
-rwxr-xr-xchallenge-111/feng-chang/raku/ch-2.raku7
-rw-r--r--challenge-111/james-smith/perl/ch-1.pl75
-rw-r--r--challenge-111/james-smith/perl/ch-2.pl89
-rw-r--r--challenge-111/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-111/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-111/luca-ferrari/raku/ch-1.p616
-rw-r--r--challenge-111/luca-ferrari/raku/ch-2.p611
-rw-r--r--challenge-111/mark-anderson/raku/ch-1.raku18
-rw-r--r--challenge-111/mark-anderson/raku/ch-2.raku12
-rwxr-xr-xchallenge-111/perlboy1967/perl/ch-1.pl44
-rwxr-xr-xchallenge-111/perlboy1967/perl/ch-2.pl53
-rw-r--r--challenge-111/perlboy1967/perl/words479828
-rwxr-xr-xchallenge-111/stuart-little/haskell/ch-1.hs39
-rwxr-xr-xchallenge-111/stuart-little/haskell/ch-2.hs16
-rwxr-xr-xchallenge-111/stuart-little/node/ch-1.js28
-rwxr-xr-xchallenge-111/stuart-little/node/ch-2.js21
-rwxr-xr-xchallenge-111/stuart-little/perl/ch-1.pl33
-rwxr-xr-xchallenge-111/stuart-little/perl/ch-2.pl44
-rwxr-xr-xchallenge-111/stuart-little/python/ch-1.py32
-rwxr-xr-xchallenge-111/stuart-little/python/ch-2.py29
-rwxr-xr-xchallenge-111/stuart-little/raku/ch-1.p630
-rwxr-xr-xchallenge-111/stuart-little/raku/ch-2.p631
-rw-r--r--challenge-111/ulrich-rieke/c/ch-1.c23
-rw-r--r--challenge-111/ulrich-rieke/c/ch-2.c39
-rw-r--r--challenge-111/ulrich-rieke/haskell/ch-2.hs16
-rw-r--r--challenge-111/ulrich-rieke/perl/ch-1.pl43
-rw-r--r--challenge-111/ulrich-rieke/perl/ch-2.pl25
-rw-r--r--challenge-111/ulrich-rieke/raku/ch-1.raku39
-rw-r--r--challenge-111/ulrich-rieke/raku/ch-2.raku23
-rw-r--r--stats/pwc-challenge-062.json429
-rw-r--r--stats/pwc-challenge-104.json259
-rw-r--r--stats/pwc-challenge-109.json249
-rw-r--r--stats/pwc-challenge-110.json636
-rw-r--r--stats/pwc-current.json462
-rw-r--r--stats/pwc-language-breakdown-summary.json66
-rw-r--r--stats/pwc-language-breakdown.json733
-rw-r--r--stats/pwc-leaders.json800
-rw-r--r--stats/pwc-summary-1-30.json40
-rw-r--r--stats/pwc-summary-121-150.json96
-rw-r--r--stats/pwc-summary-151-180.json98
-rw-r--r--stats/pwc-summary-181-210.json34
-rw-r--r--stats/pwc-summary-211-240.json66
-rw-r--r--stats/pwc-summary-31-60.json128
-rw-r--r--stats/pwc-summary-61-90.json38
-rw-r--r--stats/pwc-summary-91-120.json106
-rw-r--r--stats/pwc-summary.json72
99 files changed, 484493 insertions, 2042 deletions
diff --git a/challenge-062/jo-37/perl/ch-1.pl b/challenge-062/jo-37/perl/ch-1.pl
new file mode 100755
index 0000000000..c12b1de1cd
--- /dev/null
+++ b/challenge-062/jo-37/perl/ch-1.pl
@@ -0,0 +1,77 @@
+#!/usr/bin/perl -s
+
+=head1 NAME
+
+ch-1.pl - sort email addresses
+
+=head1 SYNOPSIS
+
+ch-1.pl [-u] [-t] [file ...]
+
+=head1 DESCRIPTION
+
+C<ch-1.pl> sorts given email addresses, optionally suppressing
+duplicates.
+The email addresses are read from the given file names or
+C<STDIN> if none is specified.
+
+The given addresses are not checked for validity beyond the existence
+of an C<at> sign.
+
+=head1 OPTIONS AND ARGUMENTS
+
+=over
+
+=item B<-u>
+
+print only unique entries
+
+=item B<-t>
+
+use example data from challenge-062 instead of I<file> or C<STDIN>
+
+=item I<file ...>
+
+read addresses from specified I<file>s.
+
+=back
+
+=cut
+
+use strict;
+use warnings;
+
+our ($u, $t);
+
+*ARGV = *DATA{IO} if $t;
+
+my @addr;
+while (<>) {
+ chomp;
+ my ($local, $domain) = split '@', $_, 2;
+ die "not an email address: $_" unless $local && $domain;
+ push @addr, {local => $local, domain => lc($domain), full => $_};
+}
+my @sorted = sort {$a->{domain} cmp $b->{domain} ||
+ lc($a->{local}) cmp lc($b->{local}) ||
+ $a->{local} cmp $b->{local}} @addr;
+
+my $result;
+if ($u) {
+ my $last;
+ my @uniq = grep {my $eq = $last &&
+ $last->{domain} eq $_->{domain} &&
+ $last->{local} eq $_->{local}; $last = $_; !$eq} @sorted;
+ $result = \@uniq;
+} else {
+ $result = \@sorted;
+}
+
+print "$_\n" for map {$_->{full}} @$result;
+
+__DATA__
+name@example.org
+rjt@cpan.org
+Name@example.org
+rjt@CPAN.org
+user@alpha.example.org
diff --git a/challenge-062/jo-37/perl/ch-2.pl b/challenge-062/jo-37/perl/ch-2.pl
new file mode 100755
index 0000000000..d23a7793d5
--- /dev/null
+++ b/challenge-062/jo-37/perl/ch-2.pl
@@ -0,0 +1,184 @@
+#!/usr/bin/perl -s
+
+use v5.16;
+use warnings;
+use PDL;
+use Math::Prime::Util qw(forperm todigits);
+use experimental qw(signatures postderef);
+
+our $verbose;
+
+die <<EOS unless @ARGV == 1;
+usage: $0 [-verbose] [--] N
+
+-verbose
+ enable trace output
+
+N
+ Find a maximum placement of queens in a N x N x N cube
+
+EOS
+
+
+# My first attempt to solve this task was a disaster. Obscure,
+# low-performance and lengthy. It was not eligible for a PWC
+# submission. A year has passed and now I found an obscure,
+# medium-performance and not so lengthy solution. The 5x5x5 cube can be
+# solved within less than 3 hours now.
+
+### Input and Output
+
+my $size = shift;
+my $cube = zeroes long, $size, $size, $size;
+$cube->badflag(1);
+my $seen = zeroes long, $size, $size, $size;
+
+say $_ for queens($cube, 0, 0, $seen)->@*;
+
+### Implementation
+
+# Get slice parameters for the square having ($x, $y) on the diagonal.
+sub nw_so ($x, $y, $size) {
+ my $d = $x - $y;
+ $d >= 0 ?
+ ([$d, $size - 1], [0, $size - $d - 1]) :
+ ([0, $size + $d - 1], [-$d, $size - 1]);
+}
+
+# Get slice parameters for the square having ($x, $y) on the
+# anti-diagonal.
+sub sw_no ($x, $y, $size) {
+ my $s = $x + $y - $size + 1;
+ $s >= 0 ?
+ ([$size - 1, $s], [$s, $size - 1]) :
+ ([$size + $s - 1, 0], [0, $size + $s - 1]);
+}
+
+# Place a queen with coordinates $queen onto the cube. Set all attacked
+# fields to BAD.
+sub place ($queen, $cube) {
+ state $bad = $cube->badvalue;
+ state $dim = $cube->dim(0);
+ my @q = $queen->list;
+
+ # Set the rook's moves to BAD
+ $cube->slice([$q[0],undef,0], [$q[1],undef,0], [])
+ .= $bad;
+ $cube->slice([$q[0],undef,0], [], [$q[2],undef,0])
+ .= $bad;
+ $cube->slice([], [$q[1],undef,0], [$q[2],undef,0])
+ .= $bad;
+
+ # Set the bishop's moves to BAD
+ # nw to so
+ my ($x, $y);
+ ($x, $y) = nw_so($q[0], $q[1], $dim);
+ $cube->slice($x, $y, [$q[2]])->diagonal(0, 1) .= $bad;
+ ($x, $y) = nw_so($q[0], $q[2], $dim);
+ $cube->slice($x, [$q[1]], $y)->diagonal(0, 2) .= $bad;
+ ($x, $y) = nw_so($q[1], $q[2], $dim);
+ $cube->slice([$q[0]], $x, $y)->diagonal(1, 2) .= $bad;
+
+ # sw to no
+ ($x, $y) = sw_no($q[0], $q[1], $dim);
+ $cube->slice($x, $y, [$q[2]])->diagonal(0, 1) .= $bad;
+ ($x, $y) = sw_no($q[0], $q[2], $dim);
+ $cube->slice($x, [$q[1]], $y)->diagonal(0, 2) .= $bad;
+ ($x, $y) = sw_no($q[1], $q[2], $dim);
+ $cube->slice([$q[0]], $x, $y)->diagonal(1, 2) .= $bad;
+
+ # Visualize the queen's position for debugging
+ set $cube, $queen->list, 1;
+}
+
+# Utilize symmetries at level 0: any index permutation may be regarded
+# as already seen as well as any mirrored position. Mark all symmetric
+# occurrences of a given position.
+sub symmetries ($pos, $seen) {
+ my $dim = $pos->dim(0);
+ my $size = $seen->dim(0);
+ my @pos = $pos->list;
+ # Permute indices.
+ forperm {
+ my $p = indx @pos[@_];
+ # Record indices and mirror indices.
+ for my $i (0 .. 2**$dim - 1) {
+ my $mirror = pdl long, todigits($i, 2, $dim);
+ $seen->indexND($p) .= 1;
+ $seen->indexND($mirror * ($size - 1 - $p) + (1 - $mirror) * $p)
+ .= 1;
+ }
+ } @pos;
+}
+
+# Find positions of remaining queens in the cube, where $level queens
+# are already present and the maximum number is known to be at least
+# $max. Try all unoccupied / not attacked fields. Cut the search tree
+# if there are less remaining fields than required for a new maximum.
+# Free fields have a zero value, fields occupied by a queen hava a value
+# of one, fields under attack of any queen have a BAD value and already
+# checked fields hold -1. This differentiation is not necessary but
+# helpful for debugging.
+sub queens ($cube, $level, $max, $seen=undef) {
+ my @max;
+ # Get free fields
+ for my $pos (whichND($cube == 0)->dog) {
+ say "<$level> pos: $pos" if $verbose && $level < $verbose;
+
+ # Avoid symmetric level-0 positions and record these.
+ $verbose && say("<$level> seen"),
+ next if defined $seen && $seen->indexND($pos);
+ symmetries($pos, $seen) if defined $seen;
+
+ # Record the current position unless there is a better solution.
+ @max = ($pos) unless @max;
+
+ # The current maximum size for this level.
+ my $cur_size = $level + @max;
+
+ # Adjust the global maximum
+ $verbose && say("<$level> max: $cur_size"),
+ $max = $cur_size if $cur_size > $max;
+
+ # Place a queen on the current free field in a cube copy.
+ my $copy = $cube->copy;
+ place($pos, $copy);
+
+ # Count remaining free fields and cut if there are not enough to
+ # proceed.
+ my $lim_max = $level + 1 + $cube->where($copy == 0)->dim(0);
+ next if $lim_max <= $max || $lim_max == $level + 1;
+
+ # Recurse into next level.
+ my $queens = queens($copy, $level + 1, $max);
+
+ # Record new max
+ @max = ($pos, $queens->@*) if $queens->@* + 1 > @max;
+ } continue {
+ # Invalidate the processed field. Set to -1 for debugging.
+ set $cube, $pos->list, -1;
+ }
+ \@max;
+}
+
+
+# Eighteen