diff options
| author | rir <rirans@comcast.net> | 2024-06-08 21:18:14 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-08 21:18:14 -0400 |
| commit | 5eb6d19fc4e8896f088ac554115e4f859647fb51 (patch) | |
| tree | 8d6d353c51c60ebd87687d0153d996a3a20f22f6 | |
| parent | 1479026d0ced20754383b592338fc692552ab21e (diff) | |
| parent | 14e4db4d669770384019246cd819e0842cc67a4e (diff) | |
| download | perlweeklychallenge-club-5eb6d19fc4e8896f088ac554115e4f859647fb51.tar.gz perlweeklychallenge-club-5eb6d19fc4e8896f088ac554115e4f859647fb51.tar.bz2 perlweeklychallenge-club-5eb6d19fc4e8896f088ac554115e4f859647fb51.zip | |
Merge branch 'manwar:master' into work
79 files changed, 3404 insertions, 1694 deletions
diff --git a/challenge-259/adam-russell/.gitignore b/challenge-259/adam-russell/.gitignore deleted file mode 100644 index d4e9a94d5e..0000000000 --- a/challenge-259/adam-russell/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.bbprojectd -.RData -.Rhistory diff --git a/challenge-259/adam-russell/twc.pdf b/challenge-259/adam-russell/twc.pdf Binary files differdeleted file mode 100644 index 181cc3d3fa..0000000000 --- a/challenge-259/adam-russell/twc.pdf +++ /dev/null diff --git a/challenge-272/adam-russell/blog.txt b/challenge-272/adam-russell/blog.txt new file mode 100644 index 0000000000..a791044ed5 --- /dev/null +++ b/challenge-272/adam-russell/blog.txt @@ -0,0 +1 @@ +http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2024/06/08 diff --git a/challenge-272/adam-russell/perl/ch-1.pl b/challenge-272/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..3564f846ea --- /dev/null +++ b/challenge-272/adam-russell/perl/ch-1.pl @@ -0,0 +1,25 @@ + + +use v5.38; + + +sub defang{ + my($c, $defanged) = @_; + $defanged = [] if !$defanged; + return $defanged if @{$c} == 0; + my $x = shift @{$c}; + if($x eq q/./){ + push @{$defanged}, q/[.]/; + } + else{ + push @{$defanged}, $x; + } + defang($c, $defanged); +} + + +MAIN:{ + say join(q//, @{defang([split //, q/1.1.1.1/])}); + say join(q//, @{defang([split //, q/255.101.1.0/])}); +} + diff --git a/challenge-272/adam-russell/perl/ch-2.pl b/challenge-272/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..bbdb2ea352 --- /dev/null +++ b/challenge-272/adam-russell/perl/ch-2.pl @@ -0,0 +1,26 @@ + + +use v5.38; + + +sub string_score{ + my($s) = shift; + my $score = 0; + my @s = map {ord $_} split //, $s; + { + my $x = shift @s; + my $y = shift @s; + $score += abs($x - $y) if $x && $y; + unshift @s, $y; + redo if @s > 1; + } + return $score; +} + + +MAIN:{ + say string_score q/hello/; + say string_score q/perl/; + say string_score q/raku/; +} + diff --git a/challenge-272/jo-37/blog.txt b/challenge-272/jo-37/blog.txt new file mode 100644 index 0000000000..39fed0c9b1 --- /dev/null +++ b/challenge-272/jo-37/blog.txt @@ -0,0 +1 @@ +https://github.sommrey.de/the-bears-den/2024/06/07/ch-272.html diff --git a/challenge-272/jo-37/perl/ch-1.pl b/challenge-272/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..9ec3849c1b --- /dev/null +++ b/challenge-272/jo-37/perl/ch-1.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use Regexp::Common 'net'; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [STR] + +-examples + run the examples from the challenge + +-tests + run some tests + +STR + "defang" string + +EOS + + +### Input and Output + +say defang(shift); + + +### Implementation +# +# For details see: +# https://github.sommrey.de/the-bears-den/2024/06/07/ch-272.html#task-1 + + +sub defang { + return /^$RE{net}{IPv4}$/ && + + s([.])([.])gr + + for shift; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is defang("1.1.1.1"), "1[.]1[.]1[.]1", "example 1"; + is defang("255.101.1.0"), "255[.]101[.]1[.]0", "example 2"; + } + + SKIP: { + skip "tests" unless $tests; + + is defang("256.0.0.1"), F(), 'invalid address'; + is defang("1.0.0.256"), F(), 'invalid address'; + } + + done_testing; + exit; +} diff --git a/challenge-272/jo-37/perl/ch-2.pl b/challenge-272/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..7f1ee3903f --- /dev/null +++ b/challenge-272/jo-37/perl/ch-2.pl @@ -0,0 +1,65 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0 '!float'; +use PDL; +use PDL::NiceSlice; +use PDL::Char; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [STR] + +-examples + run the examples from the challenge + +-tests + run some tests + +-verbose + enable trace output + +STR + an ASCII string + +EOS + + +### Input and Output + +say score(shift); + + +### Implementation +# +# For details see: +# https://github.sommrey.de/the-bears-den/2024/06/07/ch-272.html#task-2 + + +sub score { + my $s = PDL::Char->new(shift); + sum abs long($s(0:-2)) - long($s(1:-1)); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is score("hello"), 13, "example 1"; + is score("perl"), 30, "example 2"; + is score("raku"), 37, "example 3"; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} diff --git a/challenge-272/luca-ferrari/blog-1.txt b/challenge-272/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..e7579f5b4b --- /dev/null +++ b/challenge-272/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task1 diff --git a/challenge-272/luca-ferrari/blog-10.txt b/challenge-272/luca-ferrari/blog-10.txt new file mode 100644 index 0000000000..eda35729fd --- /dev/null +++ b/challenge-272/luca-ferrari/blog-10.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/[= date -%]/PerlWeeklyChallenge272.html#task2pljava diff --git a/challenge-272/luca-ferrari/blog-2.txt b/challenge-272/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..fc64e99089 --- /dev/null +++ b/challenge-272/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task2 diff --git a/challenge-272/luca-ferrari/blog-3.txt b/challenge-272/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..6cb55cedef --- /dev/null +++ b/challenge-272/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task1plperl diff --git a/challenge-272/luca-ferrari/blog-4.txt b/challenge-272/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..cb1275772f --- /dev/null +++ b/challenge-272/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task2plperl diff --git a/challenge-272/luca-ferrari/blog-5.txt b/challenge-272/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..86a012d6e5 --- /dev/null +++ b/challenge-272/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task1plpgsql diff --git a/challenge-272/luca-ferrari/blog-6.txt b/challenge-272/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..403db8c903 --- /dev/null +++ b/challenge-272/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task2plpgsql diff --git a/challenge-272/luca-ferrari/blog-7.txt b/challenge-272/luca-ferrari/blog-7.txt new file mode 100644 index 0000000000..c2fb30cccc --- /dev/null +++ b/challenge-272/luca-ferrari/blog-7.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task1python diff --git a/challenge-272/luca-ferrari/blog-8.txt b/challenge-272/luca-ferrari/blog-8.txt new file mode 100644 index 0000000000..63130d622d --- /dev/null +++ b/challenge-272/luca-ferrari/blog-8.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task2python diff --git a/challenge-272/luca-ferrari/blog-9.txt b/challenge-272/luca-ferrari/blog-9.txt new file mode 100644 index 0000000000..ce0f7adec4 --- /dev/null +++ b/challenge-272/luca-ferrari/blog-9.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/06/06/PerlWeeklyChallenge272.html#task1pljava diff --git a/challenge-272/luca-ferrari/pljava/pom.xml b/challenge-272/luca-ferrari/pljava/pom.xml index bf11a0cf59..88583e06f9 100644 --- a/challenge-272/luca-ferrari/pljava/pom.xml +++ b/challenge-272/luca-ferrari/pljava/pom.xml @@ -7,14 +7,14 @@ <groupId>PWC</groupId> <artifactId> - PWC271 + PWC272 </artifactId> <version> 1 </version> - <name>Perl Weekly Challenge 271 with package PWC271</name> - <description>Implementation of the tasks in PL/Java for PWC 271</description> + <name>Perl Weekly Challenge 272 with package PWC272</name> + <description>Implementation of the tasks in PL/Java for PWC 272</description> <properties> <project.build.sourceEncoding>US-ASCII</project.build.sourceEncoding> diff --git a/challenge-272/luca-ferrari/pljava/src/main/java/Task1.java b/challenge-272/luca-ferrari/pljava/src/main/java/Task1.java new file mode 100644 index 0000000000..8dddbce6c0 --- /dev/null +++ b/challenge-272/luca-ferrari/pljava/src/main/java/Task1.java @@ -0,0 +1,56 @@ + + + +package PWC272; + +/** + * PL/Java implementation for PWC 272 + * Task 1 + * See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-272> + * + * + * To compile on the local machine: + + $ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ # if not already set + $ mvn clean build + $ scp target/PWC272-1.jar luca@rachel:/tmp + + + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC272-1.jar', 'PWC272', true ); + select sqlj.set_classpath( 'public', 'PWC272' ); + + select pwc272.task2_pljava(); + + and then to redeploy: + + select sqlj.replace_jar( 'file:///tmp/PWC272-1.jar', 'PWC272', true ); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +import java.util.*; +import java.util.stream.*; +import java.sql.SQLException; +import java.util.logging.*; +import java.sql.ResultSet; +import java.sql.Date; + + public class Task1 { + + private final static Logger logger = Logger.getAnonymousLogger(); + + @Function( schema = "pwc272", + onNullInput = RETURNS_NULL, + effects = IMMUTABLE ) + public static final String task1_pljava( String ip ) throws SQLException { + logger.log( Level.INFO, "Entering pwc272.task1_pljava" ); + + return ip.replaceAll( "\\.", "[.]" ); + } +} diff --git a/challenge-272/luca-ferrari/pljava/src/main/java/Task2.java b/challenge-272/luca-ferrari/pljava/src/main/java/Task2.java new file mode 100644 index 0000000000..4002c64b9d --- /dev/null +++ b/challenge-272/luca-ferrari/pljava/src/main/java/Task2.java @@ -0,0 +1,63 @@ + + + +package PWC272; + +/** + * PL/Java implementation for PWC 272 + * Task 2 + * See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-272> + * + * + * To compile on the local machine: + + $ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ # if not already set + $ mvn clean build + $ scp target/PWC272-1.jar luca@rachel:/tmp + + + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC272-1.jar', 'PWC272', true ); + select sqlj.set_classpath( 'public', 'PWC272' ); + + select pwc272.task2_pljava(); + + and then to redeploy: + + select sqlj.replace_jar( 'file:///tmp/PWC272-1.jar', 'PWC272', true ); + +*/ + +import org.postgresql.pljava.*; +import org.pos |
