From 7c9386758a53c7e5c29d43164a2d57f686f6112b Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Sun, 1 Feb 2026 13:35:21 +0000 Subject: [PATCH] [Sync Iteration] go/pig-latin/1 --- solutions/go/pig-latin/1/pig_latin.go | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 solutions/go/pig-latin/1/pig_latin.go diff --git a/solutions/go/pig-latin/1/pig_latin.go b/solutions/go/pig-latin/1/pig_latin.go new file mode 100644 index 0000000..de209fd --- /dev/null +++ b/solutions/go/pig-latin/1/pig_latin.go @@ -0,0 +1,40 @@ +package piglatin + +import ( + "strings" +) + +func Sentence(sentence string) string { + words := strings.Fields(sentence) + + for i, w := range words { + // Rule 1 + if vowel(w[0]) || strings.HasPrefix(w, "xr") || strings.HasPrefix(w, "yt") { + words[i] += "ay" + continue + } + + for idx := 0; idx < len(w); idx++ { + if w[idx] == 'q' && idx+1 < len(w) && w[idx+1] == 'u' { + words[i] = w[idx+2:] + w[:idx+2] + "ay" + break + } + + if (w[idx] == 'y' && idx > 0) || vowel(w[idx]) { + words[i] = w[idx:] + w[:idx] + "ay" + break + } + } + } + + return strings.Join(words, " ") +} + +func vowel(w byte) bool { + switch w { + case 'a', 'e', 'i', 'o', 'u': + return true + default: + return false + } +}