Skip to content

Instantly share code, notes, and snippets.

@laser
Last active February 21, 2018 19:39
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 laser/b35610d033fefba853757246a92c7622 to your computer and use it in GitHub Desktop.
Save laser/b35610d033fefba853757246a92c7622 to your computer and use it in GitHub Desktop.
Iggypay Atinlay

Pig Latin Translator

What is Pig Latin?

From Wikipedia:

Pig Latin is a language game or argot in which words in English are altered, usually by adding a fabricated suffix or by moving the onset or initial consonant or consonant cluster of a word to the end of the word and adding a vocalic syllable to create such a suffix. The objective is to conceal the words from others not familiar with the rules.

Basic Rules

For words that begin with vowel sounds, one just adds "ay" to the end. Examples are:

  • "eat" = "eatay"
  • "omelet" = "omeletay"
  • "are" = "areay"

For words that begin with consonant sounds, all letters before the initial vowel are placed at the end of the word sequence. Then, "ay" is added, as in the following examples:

  • "hello" = "ellohay"
  • "latin" = "atinlay"
  • "banana" = "ananabay"
  • "happy" = "appyhay"
  • "quack" = "ackquay"
  • "yellow" = "ellowyay"

When words begin with consonant clusters (multiple consonants that form one sound), the whole sound is added to the end:

  • "cheers" = "eerschay"
  • "shesh" = "eshshay"
  • "style" = "ylestay"

Our translator will adhere to a few additional rules which you'll deduce from some example text encountered at the end of this document.

Your Assignment

We're going to build a Pig Latin translator-library in a language of your choice. We suggest that your implementation include (at least) two routines: translateWord, which translates a single word, and translateText, which translates a body of text (a sentence, a paragraph, many paragraphs, etc.) containing many words, punctuation, line breaks, et cetera.

In JavaScript, this might look like:

// Input: went
// Output: entway

function translateWord(word) {

}


// Input: I went to the store today.
// Output: Iay entway otay ethay orestay odaytay.

function translateText(text) {

}

Once you're done, you should be able to feed the following text into your translator:

Pigs. Wonderful animals. They are as smart as they are quirky. Did you know that there is a special breed of pig that lives on the shores of the Yellow Sea? They have excellent style and are generally good-hearted. I can't wait to see one myself.

...and see output that matches:

Igspay. Onderfulway animalsay. Eythay areay asay artsmay asay eythay areay irkyquay. Idday ouyay owknay atthay erethay isay aay ecialspay eedbray ofay igpay atthay iveslay onay ethay oresshay ofay ethay Ellowyay Easay? Eythay avehay excellentay ylestay anday areay enerallygay oodgay-eartedhay. Iay an'tcay aitway otay eesay oneay yselfmay.

Don't Worry!

  • Get as far as you can in 90 minutes
  • Feel free to ask questions
  • You can use the internet to look up programming-related things

Quantitative

??/10

  • hello -> ellohay (simple consonant)
  • ate -> ateay (vowel)
  • striker -> ikerstray (consonant cluster)
  • quack -> ackquay (qu special case)
  • yellow -> ellowyay (y as consonant)
  • Sea -> Easay (capitalization)
  • can't -> an'tcay (contraction)
  • good-natured -> oodgay-aturednay (hypenated words)
  • Pigs. -> Igspay. | Yellow Sea? -> Ellowyay Easay? (punctuation)
  • Pigs. Wonderful creatures. (spaces between sentences)

Qualitative

  • ??
  • ??
  • ??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment