From 4db4d024899b5873a87ccb65dc08e409d5ea494d Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Wed, 24 Dec 2025 19:13:42 -0500 Subject: [PATCH] pig-latin --- config.json | 8 ++ exercises/practice/pig-latin/.busted | 5 ++ .../practice/pig-latin/.docs/instructions.md | 46 +++++++++++ .../practice/pig-latin/.docs/introduction.md | 8 ++ .../practice/pig-latin/.meta/config.json | 19 +++++ .../practice/pig-latin/.meta/example.moon | 35 ++++++++ .../pig-latin/.meta/spec_generator.moon | 6 ++ exercises/practice/pig-latin/.meta/tests.toml | 79 +++++++++++++++++++ exercises/practice/pig-latin/pig_latin.moon | 4 + .../practice/pig-latin/pig_latin_spec.moon | 77 ++++++++++++++++++ 10 files changed, 287 insertions(+) create mode 100644 exercises/practice/pig-latin/.busted create mode 100644 exercises/practice/pig-latin/.docs/instructions.md create mode 100644 exercises/practice/pig-latin/.docs/introduction.md create mode 100644 exercises/practice/pig-latin/.meta/config.json create mode 100644 exercises/practice/pig-latin/.meta/example.moon create mode 100644 exercises/practice/pig-latin/.meta/spec_generator.moon create mode 100644 exercises/practice/pig-latin/.meta/tests.toml create mode 100644 exercises/practice/pig-latin/pig_latin.moon create mode 100644 exercises/practice/pig-latin/pig_latin_spec.moon diff --git a/config.json b/config.json index 6706ac5..4ed1298 100644 --- a/config.json +++ b/config.json @@ -446,6 +446,14 @@ "practices": [], "prerequisites": [], "difficulty": 5 + }, + { + "slug": "pig-latin", + "name": "Pig Latin", + "uuid": "cae7aa86-e805-41b3-9025-82146f585b4c", + "practices": [], + "prerequisites": [], + "difficulty": 5 } ] }, diff --git a/exercises/practice/pig-latin/.busted b/exercises/practice/pig-latin/.busted new file mode 100644 index 0000000..86b84e7 --- /dev/null +++ b/exercises/practice/pig-latin/.busted @@ -0,0 +1,5 @@ +return { + default = { + ROOT = { '.' } + } +} diff --git a/exercises/practice/pig-latin/.docs/instructions.md b/exercises/practice/pig-latin/.docs/instructions.md new file mode 100644 index 0000000..a9645ac --- /dev/null +++ b/exercises/practice/pig-latin/.docs/instructions.md @@ -0,0 +1,46 @@ +# Instructions + +Your task is to translate text from English to Pig Latin. +The translation is defined using four rules, which look at the pattern of vowels and consonants at the beginning of a word. +These rules look at each word's use of vowels and consonants: + +- vowels: the letters `a`, `e`, `i`, `o`, and `u` +- consonants: the other 21 letters of the English alphabet + +## Rule 1 + +If a word begins with a vowel, or starts with `"xr"` or `"yt"`, add an `"ay"` sound to the end of the word. + +For example: + +- `"apple"` -> `"appleay"` (starts with vowel) +- `"xray"` -> `"xrayay"` (starts with `"xr"`) +- `"yttria"` -> `"yttriaay"` (starts with `"yt"`) + +## Rule 2 + +If a word begins with one or more consonants, first move those consonants to the end of the word and then add an `"ay"` sound to the end of the word. + +For example: + +- `"pig"` -> `"igp"` -> `"igpay"` (starts with single consonant) +- `"chair"` -> `"airch"` -> `"airchay"` (starts with multiple consonants) +- `"thrush"` -> `"ushthr"` -> `"ushthray"` (starts with multiple consonants) + +## Rule 3 + +If a word starts with zero or more consonants followed by `"qu"`, first move those consonants (if any) and the `"qu"` part to the end of the word, and then add an `"ay"` sound to the end of the word. + +For example: + +- `"quick"` -> `"ickqu"` -> `"ickquay"` (starts with `"qu"`, no preceding consonants) +- `"square"` -> `"aresqu"` -> `"aresquay"` (starts with one consonant followed by `"qu`") + +## Rule 4 + +If a word starts with one or more consonants followed by `"y"`, first move the consonants preceding the `"y"`to the end of the word, and then add an `"ay"` sound to the end of the word. + +Some examples: + +- `"my"` -> `"ym"` -> `"ymay"` (starts with single consonant followed by `"y"`) +- `"rhythm"` -> `"ythmrh"` -> `"ythmrhay"` (starts with multiple consonants followed by `"y"`) diff --git a/exercises/practice/pig-latin/.docs/introduction.md b/exercises/practice/pig-latin/.docs/introduction.md new file mode 100644 index 0000000..04baa47 --- /dev/null +++ b/exercises/practice/pig-latin/.docs/introduction.md @@ -0,0 +1,8 @@ +# Introduction + +Your parents have challenged you and your sibling to a game of two-on-two basketball. +Confident they'll win, they let you score the first couple of points, but then start taking over the game. +Needing a little boost, you start speaking in [Pig Latin][pig-latin], which is a made-up children's language that's difficult for non-children to understand. +This will give you the edge to prevail over your parents! + +[pig-latin]: https://en.wikipedia.org/wiki/Pig_latin diff --git a/exercises/practice/pig-latin/.meta/config.json b/exercises/practice/pig-latin/.meta/config.json new file mode 100644 index 0000000..f7e0fc2 --- /dev/null +++ b/exercises/practice/pig-latin/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "glennj" + ], + "files": { + "solution": [ + "pig_latin.moon" + ], + "test": [ + "pig_latin_spec.moon" + ], + "example": [ + ".meta/example.moon" + ] + }, + "blurb": "Implement a program that translates from English to Pig Latin.", + "source": "The Pig Latin exercise at Test First Teaching by Ultrasaurus", + "source_url": "https://github.com/ultrasaurus/test-first-teaching/blob/master/learn_ruby/pig_latin/" +} diff --git a/exercises/practice/pig-latin/.meta/example.moon b/exercises/practice/pig-latin/.meta/example.moon new file mode 100644 index 0000000..10c6974 --- /dev/null +++ b/exercises/practice/pig-latin/.meta/example.moon @@ -0,0 +1,35 @@ +vowels = 'AaEeIiOoUu' +vowel = "[#{vowels}]" +consonant = "[^#{vowels}]" + +patterns = { + vowel: { + "^#{vowel}", + '^[Xx][Rr]', + '^[Yy][Tt]', + }, + consonant: { + "^(#{consonant}*[Qq][Uu])(.*)", + "^(#{consonant}+)([Yy].*)", + "^(#{consonant}+)(.*)", + } +} + + +translate_word = (word) -> + for patt in *patterns.vowel + if word\find patt + return word .. 'ay' + + for patt in *patterns.consonant + first, rest = word\match patt + if first and rest + return rest .. first .. 'ay' + + return word .. 'ay' + + +translate = (phrase) -> + table.concat [translate_word word for word in phrase\gmatch('[^%s]+')], ' ' + +{ :translate } diff --git a/exercises/practice/pig-latin/.meta/spec_generator.moon b/exercises/practice/pig-latin/.meta/spec_generator.moon new file mode 100644 index 0000000..03e3332 --- /dev/null +++ b/exercises/practice/pig-latin/.meta/spec_generator.moon @@ -0,0 +1,6 @@ +{ + module_imports: {'translate'}, + generate_test: (case, level) -> + body = "assert.are.equal #{quote case.expected}, translate #{quote case.input.phrase}" + indent body, level +} diff --git a/exercises/practice/pig-latin/.meta/tests.toml b/exercises/practice/pig-latin/.meta/tests.toml new file mode 100644 index 0000000..d524305 --- /dev/null +++ b/exercises/practice/pig-latin/.meta/tests.toml @@ -0,0 +1,79 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[11567f84-e8c6-4918-aedb-435f0b73db57] +description = "ay is added to words that start with vowels -> word beginning with a" + +[f623f581-bc59-4f45-9032-90c3ca9d2d90] +description = "ay is added to words that start with vowels -> word beginning with e" + +[7dcb08b3-23a6-4e8a-b9aa-d4e859450d58] +description = "ay is added to words that start with vowels -> word beginning with i" + +[0e5c3bff-266d-41c8-909f-364e4d16e09c] +description = "ay is added to words that start with vowels -> word beginning with o" + +[614ba363-ca3c-4e96-ab09-c7320799723c] +description = "ay is added to words that start with vowels -> word beginning with u" + +[bf2538c6-69eb-4fa7-a494-5a3fec911326] +description = "ay is added to words that start with vowels -> word beginning with a vowel and followed by a qu" + +[e5be8a01-2d8a-45eb-abb4-3fcc9582a303] +description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with p" + +[d36d1e13-a7ed-464d-a282-8820cb2261ce] +description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with k" + +[d838b56f-0a89-4c90-b326-f16ff4e1dddc] +description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with x" + +[bce94a7a-a94e-4e2b-80f4-b2bb02e40f71] +description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with q without a following u" + +[e59dbbe8-ccee-4619-a8e9-ce017489bfc0] +description = "first letter and ay are moved to the end of words that start with consonants -> word beginning with consonant and vowel containing qu" + +[c01e049a-e3e2-451c-bf8e-e2abb7e438b8] +description = "some letter clusters are treated like a single consonant -> word beginning with ch" + +[9ba1669e-c43f-4b93-837a-cfc731fd1425] +description = "some letter clusters are treated like a single consonant -> word beginning with qu" + +[92e82277-d5e4-43d7-8dd3-3a3b316c41f7] +description = "some letter clusters are treated like a single consonant -> word beginning with qu and a preceding consonant" + +[79ae4248-3499-4d5b-af46-5cb05fa073ac] +description = "some letter clusters are treated like a single consonant -> word beginning with th" + +[e0b3ae65-f508-4de3-8999-19c2f8e243e1] +description = "some letter clusters are treated like a single consonant -> word beginning with thr" + +[20bc19f9-5a35-4341-9d69-1627d6ee6b43] +description = "some letter clusters are treated like a single consonant -> word beginning with sch" + +[54b796cb-613d-4509-8c82-8fbf8fc0af9e] +description = "some letter clusters are treated like a single vowel -> word beginning with yt" + +[8c37c5e1-872e-4630-ba6e-d20a959b67f6] +description = "some letter clusters are treated like a single vowel -> word beginning with xr" + +[a4a36d33-96f3-422c-a233-d4021460ff00] +description = "position of y in a word determines if it is a consonant or a vowel -> y is treated like a consonant at the beginning of a word" + +[adc90017-1a12-4100-b595-e346105042c7] +description = "position of y in a word determines if it is a consonant or a vowel -> y is treated like a vowel at the end of a consonant cluster" + +[29b4ca3d-efe5-4a95-9a54-8467f2e5e59a] +description = "position of y in a word determines if it is a consonant or a vowel -> y as second letter in two letter word" + +[44616581-5ce3-4a81-82d0-40c7ab13d2cf] +description = "phrases are translated -> a whole phrase" diff --git a/exercises/practice/pig-latin/pig_latin.moon b/exercises/practice/pig-latin/pig_latin.moon new file mode 100644 index 0000000..b4873ff --- /dev/null +++ b/exercises/practice/pig-latin/pig_latin.moon @@ -0,0 +1,4 @@ +{ + translate: (phrase) -> + error 'Implement me' +} diff --git a/exercises/practice/pig-latin/pig_latin_spec.moon b/exercises/practice/pig-latin/pig_latin_spec.moon new file mode 100644 index 0000000..d186621 --- /dev/null +++ b/exercises/practice/pig-latin/pig_latin_spec.moon @@ -0,0 +1,77 @@ +import translate from require 'pig_latin' + +describe 'pig-latin', -> + describe 'ay is added to words that start with vowels', -> + it 'word beginning with a', -> + assert.are.equal 'appleay', translate 'apple' + + pending 'word beginning with e', -> + assert.are.equal 'earay', translate 'ear' + + pending 'word beginning with i', -> + assert.are.equal 'iglooay', translate 'igloo' + + pending 'word beginning with o', -> + assert.are.equal 'objectay', translate 'object' + + pending 'word beginning with u', -> + assert.are.equal 'underay', translate 'under' + + pending 'word beginning with a vowel and followed by a qu', -> + assert.are.equal 'equalay', translate 'equal' + + describe 'first letter and ay are moved to the end of words that start with consonants', -> + pending 'word beginning with p', -> + assert.are.equal 'igpay', translate 'pig' + + pending 'word beginning with k', -> + assert.are.equal 'oalakay', translate 'koala' + + pending 'word beginning with x', -> + assert.are.equal 'enonxay', translate 'xenon' + + pending 'word beginning with q without a following u', -> + assert.are.equal 'atqay', translate 'qat' + + pending 'word beginning with consonant and vowel containing qu', -> + assert.are.equal 'iquidlay', translate 'liquid' + + describe 'some letter clusters are treated like a single consonant', -> + pending 'word beginning with ch', -> + assert.are.equal 'airchay', translate 'chair' + + pending 'word beginning with qu', -> + assert.are.equal 'eenquay', translate 'queen' + + pending 'word beginning with qu and a preceding consonant', -> + assert.are.equal 'aresquay', translate 'square' + + pending 'word beginning with th', -> + assert.are.equal 'erapythay', translate 'therapy' + + pending 'word beginning with thr', -> + assert.are.equal 'ushthray', translate 'thrush' + + pending 'word beginning with sch', -> + assert.are.equal 'oolschay', translate 'school' + + describe 'some letter clusters are treated like a single vowel', -> + pending 'word beginning with yt', -> + assert.are.equal 'yttriaay', translate 'yttria' + + pending 'word beginning with xr', -> + assert.are.equal 'xrayay', translate 'xray' + + describe 'position of y in a word determines if it is a consonant or a vowel', -> + pending 'y is treated like a consonant at the beginning of a word', -> + assert.are.equal 'ellowyay', translate 'yellow' + + pending 'y is treated like a vowel at the end of a consonant cluster', -> + assert.are.equal 'ythmrhay', translate 'rhythm' + + pending 'y as second letter in two letter word', -> + assert.are.equal 'ymay', translate 'my' + + describe 'phrases are translated', -> + pending 'a whole phrase', -> + assert.are.equal 'ickquay astfay unray', translate 'quick fast run'