-
Notifications
You must be signed in to change notification settings - Fork 314
/
ch-1.pl
executable file
·62 lines (41 loc) · 1.09 KB
/
ch-1.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl -s
use v5.24;
use Test2::V0;
our ($tests, $examples);
run_tests() if $tests || $examples; # does not return
die <<EOS unless @ARGV;
usage: $0 [-examples] [-tests] [SENTENCE]
-examples
run the examples from the challenge
-tests
run some tests
SENTENCE
a sentence
EOS
### Input and Output
say qq{@{[goat_latin("@ARGV")]}};
### Implementation
#
# For details see:
# https://github.sommrey.de/the-bears-den/2024/06/19/ch-274.html#task-1
sub goat_latin {
my $na = 1;
no warnings 'uninitialized';
shift =~ s#\s*\K(?i:([^aeiou])?)(\w+)#"$2$1m" . ("a" x ++$na)#ger
}
### Examples and tests
sub run_tests {
SKIP: {
skip "examples" unless $examples;
is goat_latin("I love Perl"), "Imaa ovelmaaa erlPmaaaa", "example 1";
is goat_latin("Perl and Raku are friends"),
"erlPmaa andmaaa akuRmaaaa aremaaaaa riendsfmaaaaaa", "example 2";
is goat_latin("The Weekly Challenge"), "heTmaa eeklyWmaaa hallengeCmaaaa",
"example 3";
}
SKIP: {
skip "tests" unless $tests;
}
done_testing;
exit;
}