forked from manwar/perlweeklychallenge-club
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch-1.raku
executable file
·38 lines (31 loc) · 810 Bytes
/
ch-1.raku
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
#!/usr/bin/env raku
use v6;
my $startsWithVowel = rx/ :i ^<[aeiou]> /;
sub goatLatin($sentence) {
my @words = $sentence.comb(/\S+/);
my $a_count = 1;
for @words <-> $word {
if ($word ~~ $startsWithVowel) {
$word ~= 'ma';
}
else {
my $first = $word.substr(0,1);
my $rest = $word.substr(1);
$word = $rest ~ $first ~ 'ma';
}
$word ~= 'a' x $a_count++;
}
return @words.join(' ');
}
sub solution($sentence) {
say 'Input: $sentence = "' ~ $sentence ~ '"';
say 'Output: "' ~ goatLatin($sentence) ~ '"';
}
say "Example 1:";
solution("I love Perl");
say "\nExample 2:";
solution("Perl and Raku are friends");
say "\nExample 3:";
solution("The Weekly Challenge");
say "\nExample 4:";
solution("Bus stop Bus goes She stays Love grows Under my umbrella");