Skip to content

Instantly share code, notes, and snippets.

@peschwa
Forked from MadcapJake/platin.p6
Last active October 30, 2015 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peschwa/6c3521d3190c51f80eb8 to your computer and use it in GitHub Desktop.
Save peschwa/6c3521d3190c51f80eb8 to your computer and use it in GitHub Desktop.
Translate English to Pig Latin with ease!
multi MAIN($arg where *.IO.f) {
say translate($arg.IO.slurp).Str
}
multi MAIN($arg) {
say translate($arg).Str
}
sub translate(Str:D $english) { $english.words.map: &translate-word }
sub translate-word($word) {
# 'y' is left in the consonants because
# in English it is always a consonant when
# at the beginning of a word.
my @vowels = <a e i o u A E I O U>;
my @consonants = (("a".."z", "A".."Z") (-) @vowels).keys.cache;
given $word {
when $word.starts-with(any(@vowels)) {
$word ~ 'yay';
}
when $word.starts-with(any(@consonants)) {
samecase(
([~] $word.comb(/./).cache.rotate(1)) ~ 'ay',
$word ~ 'ay'
);
}
default { $word }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment