From 517cccfd3ccf75aab663b3ce820eae0479ed0400 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:29:20 +0200 Subject: Solution to task 1 --- challenge-286/jo-37/perl/ch-1.pl | 7 +++++++ challenge-286/jo-37/perl/ch-1a.sh | 7 +++++++ 2 files changed, 14 insertions(+) create mode 100755 challenge-286/jo-37/perl/ch-1.pl create mode 100755 challenge-286/jo-37/perl/ch-1a.sh diff --git a/challenge-286/jo-37/perl/ch-1.pl b/challenge-286/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..ad5d8fd247 --- /dev/null +++ b/challenge-286/jo-37/perl/ch-1.pl @@ -0,0 +1,7 @@ +#!/usr/bin/perl -w0777 + +use v5.12; +seek DATA, 0, 0; +say +(keys %{ { =~ /(\S+)()/g} })[0]; +__DATA__ +Hello David! diff --git a/challenge-286/jo-37/perl/ch-1a.sh b/challenge-286/jo-37/perl/ch-1a.sh new file mode 100755 index 0000000000..9386ee22f8 --- /dev/null +++ b/challenge-286/jo-37/perl/ch-1a.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# usage: ch-1.sh [N] +# call ch-1.pl N times (default: 80), count the individual printed words +# and sort by frequency + +for i in $(seq 1 ${1:-80}); do ./ch-1.pl; done | sort | uniq -c | sort -n -- cgit From 15c11d149b4513fcdaad12e0ae08a75e05c81d0a Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:29:38 +0200 Subject: Solution to task 2 --- challenge-286/jo-37/perl/ch-2.pl | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100755 challenge-286/jo-37/perl/ch-2.pl diff --git a/challenge-286/jo-37/perl/ch-2.pl b/challenge-286/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..be2640fab7 --- /dev/null +++ b/challenge-286/jo-37/perl/ch-2.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use experimental 'signatures'; + +our ($tests, $examples, $verbose); + +run_tests() if $tests || $examples; # does not return + +die < 1) { + my ($i, $k) = splice @ints, 0, 2; + push @ints, ($f *= -1) * ($k - $i) > 0 ? $k : $i; + say "@ints" if $verbose; + } + shift @ints; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is order_game(2, 1, 4, 5, 6, 3, 0, 2), 1, 'example 1'; + is order_game(0, 5, 3, 2), 0, 'example 2'; + is order_game(9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8), + 2, 'example 3'; + } + + SKIP: { + skip "tests" unless $tests; + + is order_game(3, 2, 1), 2, 'not a power of two'; + + } + + done_testing; + exit; +} -- cgit From e5648bcb029740eb843e750a5f7cd1f1d896d435 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:29:56 +0200 Subject: Blog for challenge 286 --- challenge-286/jo-37/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-286/jo-37/blog.txt diff --git a/challenge-286/jo-37/blog.txt b/challenge-286/jo-37/blog.txt new file mode 100644 index 0000000000..e22b2684cd --- /dev/null +++ b/challenge-286/jo-37/blog.txt @@ -0,0 +1 @@ +https://github.sommrey.de/the-bears-den/2024/09/13/ch-286.html -- cgit