From 784f3a7dbf8ce42f6f4f147fbcb821365772cd83 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 23 May 2023 10:58:57 +0200 Subject: Solution to task 2 --- challenge-218/jo-37/perl/ch-2.pl | 89 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 challenge-218/jo-37/perl/ch-2.pl diff --git a/challenge-218/jo-37/perl/ch-2.pl b/challenge-218/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..6c67fa4ac0 --- /dev/null +++ b/challenge-218/jo-37/perl/ch-2.pl @@ -0,0 +1,89 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0 '!float'; +use PDL; +use PDL::NiceSlice; +use Math::Prime::Util 'fromdigits'; +use experimental 'signatures'; + +our ($tests, $examples, $verbose); + +run_tests() if $tests || $examples; # does not return + +die <xchg(0, 1)->sumover < $b->dim(1) / 2; + say "final:", $b if $verbose; + + # Fromdigits accepts digits of any size, thus there is no need to + # calculate the individual numbers. + fromdigits $b->xchg(0, 1)->sumover->unpdl, 2; +} + + +### Examples and tests + +sub run_tests { + local $verbose; + + SKIP: { + skip "examples" unless $examples; + + is matrix_score(byte [0,0,1,1], [1,0,1,0], [1,1,0,0]), 39, 'example 1'; + is matrix_score(byte [[0]]), 1, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + + is matrix_score(byte [1, 1, 0, 0, 0, 1], [0, 0, 0, 1, 1, 1], + [1, 0, 1, 1, 0, 0], [0, 1, 1, 0, 0, 1], [1, 0, 0, 0, 1, 1]), + 253, 'toggle all but first columns'; + # 32 * 5 + (16 + 8 + 4 + 2 + 1) * 3 + + } + + done_testing; + exit; +} -- cgit