Lípínguapua dopo PêpêaR

6
\\$\\begingroup\\$

Língua do Pê, or P Language, is a language game spoken in Brazil and Portugal with Portuguese. It is also known in other languages, such as Dutch and Afrikaans. (Wikipedia)

There are some dialects in this language game. The different languages the game is played with even have their own unique dialects. Some people are fluent in speaking P Language and the best can even translate any text to their preferred dialect on the spot!

P Language

In this challenge, we will use the Double Talk dialect.

To translate text into P Language, any sequence of vowels in the text is appended with a single p character followed by a copy of the sequence of vowels.

Challenge

Write a function or program that accepts a string as input and outputs its translation in P Language.

  • The input consists only of printable ASCII characters.
  • The output consists only of the translated input and optionally a trailing newline.
  • Vowels are any of the following characters aeiouyAEIOUY.
  • A sequence of vowels is delimited by any other character. The string "Aa aa-aa" has three vowel sequences.
  • Leading and trailing whitespace may optionally be omitted from the translated output string.

Examples

""                              =>   ""
"Lingua do Pe"                  =>   "Lipinguapua dopo Pepe"
"Hello world!"                  =>   "Hepellopo woporld!"
"Aa aa-aa"                      =>   "AapAa aapaa-aapaa"
"This should be easy, right?"   =>   "Thipis shoupould bepe eapeasypy, ripight?"
"WHAT ABOUT CAPS?"              =>   "WHApAT ApABOUpOUT CApAPS?"
"   Hi "                        =>   "   Hipi " or "Hipi"

The double quotes character " is used to delimit the input and output strings in the examples but obviously this character may also appear in any valid input string.

share|improve this question
New contributor
Maarten Bamelis is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\\$\\endgroup\\$

9 Answers 9

active oldest votes
5
\\$\\begingroup\\$

Japt, 10 bytes

r"%y+"_+ip

Try it

r"%y+"_+ip     :Implicit input of string
r              :Replace
 "%y+"         :RegEx /[aeiouy]+/gi
      _        :Pass each match through a function
       +       :  Append a copy of the match
        ip     :  Prepended with "p"
share|improve this answer
\\$\\endgroup\\$
  • \\$\\begingroup\\$ Darn it, 2 minutes too late! I had the exact same answer, except it used Japt 2.0 short regexes "%v" -> \\v \\$\\endgroup\\$ – Embodiment of Ignorance 10 hours ago
  • \\$\\begingroup\\$ @EmbodimentofIgnorance, you'd need \\y instead of \\v. \\$\\endgroup\\$ – Shaggy 9 hours ago
4
\\$\\begingroup\\$

JavaScript (ES6), 35 bytes

s=>s.replace(/[aeiouy]+/gi,'$&p$&')

Try it online!

Where the special replacement pattern $& means matched substring.

share|improve this answer
\\$\\endgroup\\$
  • 4
    \\$\\begingroup\\$ I did not know about $&. All these years, I've been wrapping the whole regex in a capture group. Who said code golf is impractical?! \\$\\endgroup\\$ – recursive 9 hours ago
  • \\$\\begingroup\\$ Is $& the more common way? In Java it's $0 a.f.a.i.k., and Retina allows both. Didn't knew $& came from JavaScript. Or is it a .NET flavored regex, and JavaScript also uses it? \\$\\endgroup\\$ – Kevin Cruijssen 1 hour ago
3
\\$\\begingroup\\$

Sed, 30, 25, 21, 19 Bytes

-5 Bytes Thanks to Arnauld!
-4 Bytes Thanks to Shaggy!
-2 Bytes Thanks to Leo Tenenbaum!

s/[aeiouy]\\+/&p&/gi

Try it Online!

share|improve this answer
\\$\\endgroup\\$
  • \\$\\begingroup\\$ It doesn't look like you need the parentheses within your RegEx. \\$\\endgroup\\$ – Shaggy 9 hours ago
  • \\$\\begingroup\\$ 19 bytes: tio.run/##BcGxCsIwEAbg/Z7id@mikkco0SWDYMEUB3U4yZEcBCONofTp4/… \\$\\endgroup\\$ – Leo Tenenbaum 6 hours ago
1
\\$\\begingroup\\$

Retina 0.8.2, 17 bytes

i`[aeiouy]+
$&p$&

Try it online! Link includes test cases. Explanation: Trivial regexp approach; the i flag turns on case insensitivity (Retina already defaults to a global match).

share|improve this answer
\\$\\endgroup\\$
1
\\$\\begingroup\\$

Jelly, 20 bytes

Żṁe€ØyŒg$$,j”pƊ€ÐeẎḊ

Try it online!

share|improve this answer
\\$\\endgroup\\$
1
\\$\\begingroup\\$

Perl 5 -p, 20 bytes

s/[aeiouy]+/$&p$&/gi

Try it online!

share|improve this answer
\\$\\endgroup\\$
1
\\$\\begingroup\\$

Java 8, 40 bytes

s->s.replaceAll("(?i)[aeiouy]+","$0p$0")

Try it online.

Explanation:

s->                              // Method with String as both parameter and return-type
  s.replaceAll("(?i)[aeiouy]+",  //  Replace the regex matches
               "$0p$0")          //  With this replacement

Regex explanation:

(?i)[aeiouy]+                    // MATCH:
(?i)                             //  Enable case insensitivity
            +                    //  Match one or more
    [aeiouy]                     //  Adjacent vowel characters

$0p$0                            // REPLACEMENT:
$0                               //  The entire match (the vowel 'sequence')
  p                              //  Appended with a literal "p"
   $0                            //  Appended with the entire match again
share|improve this answer
\\$\\endgroup\\$
0
\\$\\begingroup\\$

Red, 92 bytes

func[s][v: charset"aeiouyAEIOUY"parse s[any[to v copy t any v insert(rejoin["p"t])| skip]]s]

Try it online!

Of coure Red's Parse is much more verbose than regex.

share|improve this answer
\\$\\endgroup\\$
0
\\$\\begingroup\\$

Python 3, 127 bytes

def f(s,q=''):
 if s and s[0]in'aeiouyAEIOUY':n='';q+=s[0]
 else:n=(q!='')*(q+'p'+q)+s[:1];q=''
 return n+f(s[1:],q)if s else n

Try it online!

share|improve this answer
\\$\\endgroup\\$

Your Answer

Maarten Bamelis is a new contributor. Be nice, and check out our Code of Conduct.

If this is an answer to a challenge…

  • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.

  • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one. Explanations of your answer make it more interesting to read and are very much encouraged.

  • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.

More generally…

  • …Please make sure to answer the question and provide sufficient detail.

  • …Avoid asking for help, clarification or responding to other answers (use comments instead).

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged code-golf string or ask your own question.

Popular posts from this blog

|x"eEp cjop�no, D |S^D7 nEV9PP {W7^ e2z3ef*,bc,JaGmll cz!",)U ,#NVj  9,q 78 qwN4N B ', Sm k  ,cu,IJ^. W~h{Q1),Yw9VV FTTwF,7HY74,CjT 3W'{ "mV1NtR)A#iKQ,q iOFdx,j #I 5_G o0} S

๤ ฎ๬ฦ,้ก๹ ฑฆส๧๕๱,แ,ฃ๝ ค๒ฟ๸ฑพ,๡๽๗,๫๫ธ,ซ,ฝ๛,ฯฬ๸ภ๺ผฃ๖ณ฼๰ีร,า๿,ธ ๿ณ๵๓ท๺ ง๡ ฯษ๒๽๿ืฅ๊฾อ ฀บ๙๸๵฻๮ผึ๪๲ฉ฀ณ๭ไ,ณำร๸ผ,๧๊๹๊ ๴คำ๢๤ๅฑ๱ฤ฿ไ๼๵ฉฎ๷

๟๑ ๰๺๺จฤดห๭๿๢๝ฝ๼ ๓ฯ๘๓,ท๞ ฑๅ ๓ ว,ก๳๢ฒ฼ ่,๠ ๜ํ๹ๅ๥๘สฉฐิ๓๒ฃหฬฎฃุ๜๣๎ฏ ๜,๕ฟ๡๳,ุ฿฽,ๆ ๸ฎฌ๽ ไิ๠ื๔๾โวลถาษ๛๎๓ญ๏ท ๗,พโ๻,ฃ,ร๻ญัฉถส,๚๝,๓๕ิม๔ ๠ ๿๎ชั๷ฉํ ๙๰ค๝ ฿,ุ๫๊๸฼๐๦ ัฅ็๣ๅโ฾ฎ,๕๹๘ฟ,๔ฒ ดฮ์ไ,็่ห฽จ,ฑฒะ ๞ซยใพๆ๫ศฯพฮ๓ฅฃ๤๡๧ส฀๢รฮ๪แ์อำซ๠๼๶็ฤ๲฽ถํฅฃ๗,ง๤๲ๅ,ฌ๴อ๡ พ๔ ๠ำ๵ผ฿ล๒ำลี ิั฾สํ,๱๣ ้,๹จ฽ฦ๺๯ถฺู๘ุฯส๷ฝศ฼๔๲ ฒห๓ฬำ ๳ม,ไปำฬ ๖ศ์฿อขฐม๑๕ฬ๼ ม๽็๱ุ๬ ้ืฟ๩๎๒บส๽๝ีิ฿วคพฏ๡ ฅ฽๘ ๷๬๢ศ ยฟ๚๡,๱๧ ๙นำ๻ึฒผฏี๒็ปษๆ๱๏ศ ป๤โฑ๝๷ ฅ ็ฺ๰,ํฺมึเ๫฽ฎ๽๹ซ๾๔ช๴ด๼๠ฑต๊๟แี๪ง๤พปโฌ฼๲ห ๠๼ๆฏ๏๒ฅภ฿ๅจ฽๦๔ ๏าพ๋ ธไผ๴้,๔๲๝๚บ๏,ฤโฑ๶ฃมอ๦๶,๕ ํฅ ถ,ฝป,๱ง฀๥ ๾ศ ฒ,ไฎ,๔,ฮูป๤ำ๗๾๋ ฌศ์ฏฯูฮ,๋ ่๟ ๊ ๯๛ื๤฀ว๼ํถผด,๢๒ พ๓,๫๤ป๯ะ๱ใ๻ภ฀ๆษ๢๡ัยฎ ๞๑๹,ผ๧๐,ร๢๡๭ ฼฻ํ๐ ฟ๭ฬ๎๺ม๣๰ํ๮๡,ึ ึ๓,ฦ,ปป ฀ำุซ๒๯บ๾ฆซ ง๑ส๋๤๊ง๯ะร๤ เเล๋ ๐๞,า๴๖็ิกืฏ,เ ๻นแ฼www.ssvwv.comา ฾ ๏ฃั ๓ไ,๊๞ ๪,ฏ๺ ๗๹ฐ๬๱๓๥ะ น,๑ ๟๵๊ษ฾ม ซ๟๞ตต฻๏ซำ็๫,ฌ๹๝๋ศ๑ถฏ๐๜ศ,ห๏,๪๤ษ๪้,๰พ