From b13afa65925584f7ae3fecad2750faf19f632d5e Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Mon, 22 Apr 2024 18:12:18 +0200 Subject: Solution to task 1 --- challenge-266/jo-37/perl/ch-1.pl | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 challenge-266/jo-37/perl/ch-1.pl diff --git a/challenge-266/jo-37/perl/ch-1.pl b/challenge-266/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..f636db4c2e --- /dev/null +++ b/challenge-266/jo-37/perl/ch-1.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl -s + + +use v5.24; +use Test2::V0; +use List::MoreUtils 'singleton'; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die < Date: Mon, 22 Apr 2024 18:12:34 +0200 Subject: Solution to task 2 --- challenge-266/jo-37/perl/ch-2.pl | 88 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 challenge-266/jo-37/perl/ch-2.pl diff --git a/challenge-266/jo-37/perl/ch-2.pl b/challenge-266/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..9e6de958e0 --- /dev/null +++ b/challenge-266/jo-37/perl/ch-2.pl @@ -0,0 +1,88 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0 '!float'; +use PDL; +use PDL::NiceSlice; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <where_both(identity($m) | identity($m)->(-1:0)); + + all($on_x) && !any($off_x); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is is_x([ [1, 0, 0, 2], + [0, 3, 4, 0], + [0, 5, 6, 0], + [7, 0, 0, 1], + ]), T(), 'example 1'; + + is is_x([ [1, 2, 3], + [4, 5, 6], + [7, 8, 9], + ]), F(), 'example 2'; + + is is_x([ [1, 0, 2], + [0, 3, 0], + [4, 0, 5], + ]), T(), 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + + is is_x([ [1, 0, 0, 2], + [0, 3, 4, 0], + [0, 5, 6, 0], + [7, 0, 0, 0], + ]), F(), 'zero on X'; + + is is_x([ [1, 0, 0, 2], + [0, 3, 4, 0], + [0, 5, 6, 1], + [7, 0, 0, 1], + ]), F(), 'nonzero off X'; + } + + done_testing; + exit; +} -- cgit From 9e8d43cc014d6347082d65c6b5d060401e3e82f5 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Mon, 22 Apr 2024 18:12:57 +0200 Subject: Blog for challenge 266 --- challenge-266/jo-37/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-266/jo-37/blog.txt diff --git a/challenge-266/jo-37/blog.txt b/challenge-266/jo-37/blog.txt new file mode 100644 index 0000000000..93ee41023d --- /dev/null +++ b/challenge-266/jo-37/blog.txt @@ -0,0 +1 @@ +https://github.sommrey.de/the-bears-den/2024/04/26/ch-266.html -- cgit