From ecb93fa735b7c0895a3d5c5350828f3333ed503f Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Fri, 19 Jul 2024 14:22:20 +0200 Subject: Solution to task 1 --- challenge-278/jo-37/perl/ch-1.pl | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 challenge-278/jo-37/perl/ch-1.pl (limited to 'challenge-278') diff --git a/challenge-278/jo-37/perl/ch-1.pl b/challenge-278/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..7e1f466199 --- /dev/null +++ b/challenge-278/jo-37/perl/ch-1.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <[0], + sort {$a->[1] <=> $b->[1]} + map [/(.+?)(\d+)$/], + split /\s+/, shift; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is sort_string("and2 Raku3 cousins5 Perl1 are4"), + "Perl and Raku are cousins", "example 1"; + + is sort_string("guest6 Python1 most4 the3 popular5 is2 language7"), + "Python is the most popular guest language", "example 2"; + + is sort_string("Challenge3 The1 Weekly2"), + "The Weekly Challenge", "example 3"; + } + + SKIP: { + skip "tests" unless $tests; + + is sort_string("twelve12 one1 two2 eight8 six6 seven7 five5 ten10 four4 eleven11 nine9 three3"), + "one two three four five six seven eight nine ten eleven twelve", + "more than ten"; + } + + done_testing; + exit; +} -- cgit