From 27f37cb7c2ac5d762c1e00427c578e8cd4b9827a Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Thu, 23 May 2024 20:55:46 +0200 Subject: Solution to task 1 --- challenge-270/jo-37/perl/ch-1.pl | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 challenge-270/jo-37/perl/ch-1.pl diff --git a/challenge-270/jo-37/perl/ch-1.pl b/challenge-270/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..932b41e780 --- /dev/null +++ b/challenge-270/jo-37/perl/ch-1.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0 '!float'; +use PDL; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <sumover->dummy(0) * $m->xchg(0, 1)->sumover == 1)->nelem; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is count_special([ + [1, 0, 0], + [0, 0, 1], + [1, 0, 0],]), 1, 'example 1'; + is count_special([ + [1, 0, 0], + [0, 1, 0], + [0, 0, 1],]), 3, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} -- cgit From 861a6188f3cb0ad2aa75c8e9a1f7921f5d9f0137 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Thu, 23 May 2024 20:56:08 +0200 Subject: Solution to task 2 --- challenge-270/jo-37/perl/ch-2.pl | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 challenge-270/jo-37/perl/ch-2.pl diff --git a/challenge-270/jo-37/perl/ch-2.pl b/challenge-270/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..05435dc0ed --- /dev/null +++ b/challenge-270/jo-37/perl/ch-2.pl @@ -0,0 +1,78 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0 '!float'; +use PDL v2.077; # for minimum_n_ind +use PDL::NiceSlice; +use experimental 'signatures'; + +our ($tests, $examples, $verbose, $x, $y); + +run_tests() if $tests || $examples; # does not return + +die <dim(0) < 2; + my $target = maximum $ints; + return $x * ($ints->dim(0) * $target - sum($ints)) if $y >= 2 * $x; + my $cost = 0; + while () { + say $ints if $verbose; + my $min = $ints->index(minimum_n_ind($ints, 2)); + return $cost + $x * ($target - $min((0))) if $min((1)) == $target; + $min += 1; + $cost += $y; + } +} + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is equalize_array(3, 2 ,=> 4, 1), 9, 'example 1'; + is equalize_array(2, 1 ,=> 2, 3, 3, 3, 5), 6, 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + } + + done_testing; + exit; +} -- cgit From 051e263a203e32a05e73595731cf617aa7cd63a0 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Thu, 23 May 2024 20:56:28 +0200 Subject: Blog for challenge 270 --- challenge-270/jo-37/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-270/jo-37/blog.txt diff --git a/challenge-270/jo-37/blog.txt b/challenge-270/jo-37/blog.txt new file mode 100644 index 0000000000..fc81d9be72 --- /dev/null +++ b/challenge-270/jo-37/blog.txt @@ -0,0 +1 @@ +https://github.sommrey.de/the-bears-den/2024/05/24/ch-270.html -- cgit