From 3fb84dc0aedd604360532fa6442f756389d4d677 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Tue, 8 Nov 2022 21:09:55 +0100 Subject: Solution to task 1 --- challenge-190/jo-37/perl/ch-1.pl | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 challenge-190/jo-37/perl/ch-1.pl diff --git a/challenge-190/jo-37/perl/ch-1.pl b/challenge-190/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..d191a344c2 --- /dev/null +++ b/challenge-190/jo-37/perl/ch-1.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die < Date: Tue, 8 Nov 2022 21:04:27 +0100 Subject: Solution to task 2 --- challenge-190/jo-37/perl/ch-2.pl | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 challenge-190/jo-37/perl/ch-2.pl diff --git a/challenge-190/jo-37/perl/ch-2.pl b/challenge-190/jo-37/perl/ch-2.pl new file mode 100755 index 0000000000..185ebd1406 --- /dev/null +++ b/challenge-190/jo-37/perl/ch-2.pl @@ -0,0 +1,97 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die < # a capture group named "REC" as: + (?{local @p = @p; push @p, $1}) + # Create a backtracking-safe copy of the + # current (incomplete) partition and + # record the previously captured part of + # the string. + ) + ) + }x; + + # Loop over the found partitions and convert the codes into their + # corresponding encoded ASCII characters. + map {pack 'C*', map ord('A') + $_ - 1, @$_} @part; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is [decode(11)], [qw(AA K)], 'Example 1'; + is [decode(1115)], [qw(AAAE AAO AKE KAE KO)], 'Example 2'; + is [decode(127)], [qw(ABG LG)], 'Example 3'; + + } + + SKIP: { + skip "tests" unless $tests; + + is decode(130), F(), 'invalid zero'; + is [decode(120)], ['AT'], 'valid zero'; + is [decode(3 x 128)], ['C' x 128], 'long code'; + } + + done_testing; + exit; +} -- cgit