# Covfefify a string

In this challenge, you must take a string matching the regex ^[a-zA-Z]+$ or whatever is reasonable (you don't have to consider uppercase or lowercase letters if you want) (you may assume the string is long enough, and has the right structure for all the operations), and output another string, produced similarly to word at the end of a recent dadaist tweet by the POTUS ("Despite the constant negative press covfefe"). ## How to covfefify a string: ### First, get the first sound group (made up terminology). How do you do this? Well: • Find the first vowel (y is also a vowel)  v creation  • Find the first consonant after that  v creation  • Remove the rest of the string creat  That is your first sound group. ### Next step: Get the last consonant of the sound group t  and replace it with the voiced or voiceless version. To do this, find the letter in this table. Replace with the letter given (which may be the same letter) b: p c: g d: t f: v g: k h: h j: j k: g l: l m: m n: n p: b q: q r: r s: z t: d v: f w: w x: x z: s  so, we get d  Then, take the next vowel after that consonant. You can assume that this consonant is not at the end of the string. Join these two together, then repeat it twice: didi  Concatenate this to the first sound group: creatdidi  You're done: the string is covfefified, and you can now output it. Test cases: coverage: covfefe example: exxaxa programming: progkaka (the a is the first vowel after the g, even though it is not immediately after) code: codtete president: preszizi  This is , so please make your program as short as possible! • "x" should technically map onto "gz". "qu" should map onto "gw". – Steve Bennett Jun 5 '17 at 5:34 • Answers over 140 characters should be disqualified – Sandy Gifford Jun 7 '17 at 15:27 • Unfortunately it is impossible to do this in TrumpScript :( – user69279 Jun 14 '17 at 22:09 • @ThePlasmaRailgun dude... – Sandy Gifford Dec 20 '17 at 14:57 • @ThePlasmaRailgun It was a joke, since tweets have to be 140 characters or less. – Esolanging Fruit Dec 31 '17 at 22:14 ## 40 Answers # sed, 106 (105+1) bytes This is sed with the -E flag, which apparently counts for one byte. s/([aoeuiy][^aoeuiy])[^aoeuiy]*(.).*/\1\2/ h s/.*(..)/\1\1/ y/bcdfgkpstvz/pgtvkgbzdfs/ x s/.$//
G
s/\n//g


Try it online!

# C#, 584 581 bytes

-3 bytes thanks to Destructible Lemon

This is my first submission on Code Golf and on Stack Exchange in general. I know that C# isn't a great golfing language and this probably isn't completely optimized but I wanted to give it a shot :p. Any tips are welcome!

Golfed Version:

namespace System{class B{static void Main(string[]args){var s="creation";var t="aeiou";int i=0,j=0,l=s.Length;char c=' ',f=' ';for(int x=0;x++<l;){if(t.IndexOf(s[x])>=0){i=x;break;}}for(int x=i;x++<l;){if(!(t.IndexOf(s[x])>=0)){j=x;c=s[x];for(int y=x;y++<l;){if (t.IndexOf(s[y])>=0){f=s[y];goto W;}}}}W:switch(c){case'b':c='p';break;case'c':c='g';break;case'd':c='t';break;case'f':c='v';break;case'g':c='k';break;case'k':c='j';break;case'p':c='b';break;case's':c='z';break;case't':c='d';break;case'v':c='f';break;case'z':c='s';break;}Console.Write(s.Substring(0,l-i-1)+c+f+c+f);}}}


Readable Version:

namespace System
{
class B
{
static void Main(string[] args)
{
var s = "creation";
var t = "aeiou";
int i = 0, j = 0, l = s.Length;
char c = ' ', f = ' ';
for (int x = 0; x++ < l; )
{
if (t.IndexOf(s[x]) >= 0)
{
i = x; break;
}
}
for (int x = i; x++ < l;)
{
if (!(t.IndexOf(s[x]) >= 0))
{
j = x; c = s[x];
for (int y = x; y++ < l;)
{
if (t.IndexOf(s[y]) >= 0)
{
f = s[y];
break;
}
}
}
}
switch (c)
{
case 'b': c = 'p';
break;
case 'c': c = 'g';
break;
case 'd': c = 't';
break;
case 'f': c = 'v';
break;
case 'g': c = 'k';
break;
case 'k': c = 'j';
break;
case 'p': c = 'b';
break;
case 's': c = 'z';
break;
case 't': c = 'd';
break;
case 'v': c = 'f';
break;
case 'z': c = 's';
break;
}
Console.Write(s.Substring(0, l - i - 1) + c + f + c + f);
}
}
}

• I'm no expert, but I think you can add the incrementation to the comparator in the for loop, that is, x++ < l, or something (maybe l > x++ if the first doesn't work). not sure though – Destructible Lemon Jul 22 '17 at 2:51
• @DestructibleLemon Thanks for the tip! – Brandon Hao Jul 24 '17 at 14:18

# Python 3, 194 bytes

f=lambda s,g='aeiouy':min([s.index(l)for l in g if l in s])
C='bcdfghjklmnpqrstvwxyz'
q=input()
v=f(q)
c=f(q[v:],C)+v+1
S=('pgtvkhjglmnbqrzdfwxs'[C.index(q[c-1])]+q[f(q[c:])+c])*2
print(q[:c]+S)


Try it online!

I've had this coded since the week of the challenge, but was discouraged to post in its then-current state (which also happens to be the current state) because of all the 80-byte regex answers.

But hey, what the hell. Here's another non-esoteric, non-regex answer, six months late to the party.

-30 bytes from typing out the consonants in a string rather than using a list comprehension

• Your TIO gives an error. – FlipTack Jan 4 '18 at 7:49

# Vim, 107 keystrokes

Who needs Java, Python 3, Modern Pascal 2.0, C#, Python 2, R, Go, C, BlitzMax, Javascript, Crystal, Clojure, Lua, Matlab/Octave, Haskell and PHP when you have vim?

i ⎋o⏎bcdfghjklmnpqrstvwxz⏎pgtvkhjglmnbqrzdfwxs⎋1Ghqy/[aeiouy]⏎q/[^aeiouy]⏎mz@yylzpld$yhjpg*jylzpy2lPjdGX  ⎋ is the Escape key and ⏎ is the Return key ## Explanation i ⎋ Insert a space before the first character o⏎bcdfghjklmnpqrstvwxz⏎ Insert the character data pgtvkhjglmnbqrzdfwxs⎋1Gh qy/[aeiouy]⏎q Find the first vocal after the space /[^aeiouy]⏎mz Find the next consonant and add a marker @yylzp Find the next vocal and put it after the consonant ld$                         Delete the rest of the world
yhjpg*                      Search for the consonant in the first row of the character data
jyl                         Copy the character in the same position in the second row
zpy2lPjdGX                 Paste it after the last vowel and repeat the two last characters

• I may be wrong, but it doesn't look like [aeiou] and [^aeiou] account for the fact that, in this challenge, y is considered a vowel. – FlipTack Jan 3 '18 at 16:32

# SmileBASIC, 185179 168 bytes

This is an even more golfed version of snail_'s answer.

INPUT W$DEF V(C)RETURN.>INSTR(@AEIOUY,W$[C])END@L?W$[I]; I=I+1ON!V(I-1)&&V(I)GOTO@L X$=W$[I]WHILE V(I)I=I+1WEND?X$;((X$+@PGTVKGBZDFS)[INSTR(@BCDFGKPSTVZ,X$)+1]+W$[I])*2  ## Ungolfed: 'input INPUT WORD$
'function returns true if the character at POS is a consonant
DEF CONSONANT(POS)
RETURN INSTR(@AEIOUY,WORD$[POS])<0 END 'scan through the word until there's a vowel followed by a consonant REPEAT PRINT WORD$[I];
I=I+1
UNTIL !CONSONANT(I-1) && CONSONANT(I)
'Store and print the final letter of the "normal" section
LASTNORMAL$=WORD$[I]
PRINT LASTNORMAL$; 'Find the next vowel WHILE CONSONANT(I) I=I+1 WEND 'If last normal letter is one of "BCDFGKPSTVZ", replace with corresponding letter in "PGTVKGBZDFS" 'otherwise don't change it CORRUPTED$=(LASTNORMAL$+@PGTVKGBZDFS)[INSTR(@BCDFGKPSTVZ,LASTNORMAL$)+1]
'print the "corrupted" letter and the vowel that was found earlier, twice.
PRINT (CORRUPTED$+WORD$[I])*2


# Python 3, 170 149 bytes

def f(s):g=lambda x,y:[(i in"aeiouy")for i in s].index(x,y);j=g(0,g(1,0));c=s[j];z="ckbdfszvtpgg"+c;return s[:j+1]+2*((c+z)[-z.index(c)-2]+s[g(1,j)])


Try it online!

A more readable version:

def f(s):
n = [ (i in "aeiou") for i in s ]
i = n.index(1)
j = n.index(0, i)
k = n.index(1, j)
c = s[j]
v = s[k]
z = "ckbdfszvtpgg" + c
r = (c+z)[-z.index(c)-2]
return s[:j+1] + r + v + r + v


i, j, and k are the indices of the first vowel, the first consonant after that c, and the first vowel after that v respectively.

• Welcome to the site and nice first answer! I've added in a link to an online interpreter so that others can test and verify your code. Note that you can save a few bytes by changing the indentation to a single space on each line. For more tips, check out our Tips for golfing in Python page! – caird coinheringaahing Mar 10 at 20:53
• Welcome to the site! More than just a single space, you can actually get rid of all of the indentation by using ;. You also have an extra space after the first in. Try it online! – Wheat Wizard Mar 10 at 20:55
• Thank you guys for the optimizations! – Roy Mar 11 at 21:22

# Perl, 90 bytes (89 + 1)

I see that I've already been beaten by another Perl answer, but I'll post this anyway. Run with -p.

s/[aeiouy](.)\K[^aeiouy]*(.).*$//;$x=$1=~y/bcdfgkpstvz/pgtvkgbzdfs/r;$_.="$x$2"x2


## Go, 298 bytes

func c(l string)string{v:="aeiouy";c:="bcdfghjklmnpqrstvwxz";r:="pgtvkhjglmnbqrzdfwxs";b:=l[0:strings.IndexAny(l,v)+1];t:=strings.SplitAfterN(l,b,2)[1];i:=strings.IndexAny(t,c);b=b+t[0:i+1];x:=string(r[strings.IndexAny(c,string(t[i]))]);z:=string(t[i:][strings.IndexAny(t[i:],v)]);return b+x+z+x+z}

• Welcome to PPCG! – Martin Ender Jun 19 '17 at 14:46

# Modern Pascal 2.0, 415, 396 bytes

function c(S:String):String;
var L,M,I:Longint; const v='aeiouy'; o='_pgt_vkh_jglmn_bqrzd_fwx_s';
begin S:=Lowercase(S); Result:=S;
For l:=1 to length(S) do if pos(S[l],v)>0 then Break;
For M:=l to length(S) do if pos(S[M],v)=0 then begin
Result:=Copy(S,1,M);I:=Ord(S[M])-96;Delete(S,1,M);
For L:=1 to Length(S) do If Pos(S[l],v)>0 then begin
Result+=o[I]+S[L]+o[I]+S[L];Break;End;Break;End;End;


// Author of Modern Pascal

• this is not 415 bytes. please trim spaces and actually make it 415 bytes to have that score. also the function name can be golfed – Destructible Lemon Jun 12 '17 at 23:52
• made smaller by unformatting. Could go even smaller, as modern pascal does not enforce the grammer of then a wasted heartbeat in parsing. – Ozz Nixon Jun 13 '17 at 17:46
• if you can go even smaller then you should – Destructible Lemon Jun 13 '17 at 22:17

# Excel, 207 bytes

=LET(s,A1,x,SEQUENCE(LEN(s)),c,ISERROR(FIND(MID(s,x,1),"aeiouy")),k,MIN(IF(c*(x>MIN(IF(c,"",x))),x,"")),q,MID(s,k,1),m,"bcdfkszgvtgp"&q,n,MID(q&m,14-FIND(q,m),1)&MID(s,MIN(IF(c+(x<k),"",x)),1),LEFT(s,k)&n&n)