394
\$\begingroup\$

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!

\$\endgroup\$
8
  • 8
    \$\begingroup\$ "x" should technically map onto "gz". "qu" should map onto "gw". \$\endgroup\$ Jun 5, 2017 at 5:34
  • 83
    \$\begingroup\$ Answers over 140 characters should be disqualified \$\endgroup\$ Jun 7, 2017 at 15:27
  • 19
    \$\begingroup\$ Unfortunately it is impossible to do this in TrumpScript :( \$\endgroup\$
    – user69279
    Jun 14, 2017 at 22:09
  • 6
    \$\begingroup\$ @ThePlasmaRailgun dude... \$\endgroup\$ Dec 20, 2017 at 14:57
  • 13
    \$\begingroup\$ @ThePlasmaRailgun It was a joke, since tweets have to be 140 characters or less. \$\endgroup\$ Dec 31, 2017 at 22:14

49 Answers 49

1
2
3
\$\begingroup\$

SmileBASIC 3, 195 bytes

Very late to this question, but how could I resist a good challenge for SmileBASIC 3? Features like iterating over a sequence or manipulating a string aren't quite as robust as other languages, so this is a bit of a challenge to do it as small as possible. Assumes words are UPPERCASE.

V$="AEIOUY
LINPUT W$REPEAT I=I+1UNTIL.<=INSTR(V$,W$[I-1])&&.>INSTR(V$,W$[I])J=I
WHILE.>INSTR(V$,W$[J])J=J+1WEND?LEFT$(W$,I+1)+("PGTVKHJGLMNBQRZDFWXS"[INSTR("BCDFGHJKLMNPQRSTVWXZ",W$[I])]+W$[J])*2

Detailed explanation here!

\$\endgroup\$
3
\$\begingroup\$

05AB1E, 35 bytes

1ú.γžOså}R`¦??н©?н®ì.•gÍĆdQ¸G•Â‡D?,

Try it online!

1ú                 # prepend the input with a space
                   # (this ensures the word doesn’t start with a vowel)
  .γ    }          # group characters by:
    žO             #  built-in constant "aeiouy"
      så           #  is the character in that string?
         R         # reverse the list of groups
          `        # dump all on the stack (first group on top)
¦                  # remove the space we added earlier
 ?                 # print the first consonant group
  ?                # print the first vowel group
   н               # get the first letter of the second consonant group
    ©              # save it in the register
     ?             # print it
      н            # get the first letter of the second vowel group
       ®           # restore the consonant from the register
        ì          # prepend, giving a consonant-vowel pair
.•gÍĆdQ¸G•         # compressed string "pgtvgzskfdcb"
          Â        # push a reversed copy of it
           ‡       # transliterate (b => p, c => g, ...)
            D      # duplicate the transliterated pair
             ?,    # print both copies (with a newline the second time)
\$\endgroup\$
3
\$\begingroup\$

PowerShell, 324 bytes

$v="[aeiouy]";$f=[regex]::match($w,$v).index+1;$s=[regex]::match($w.substring($f),"[^aeiouy]").index;$t=[regex]::match($w.substring($f),$v);
$c=@{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'};
$r=$c["$($w[($f+$s)])"];$w.substring(0,$f+$s+1)+"$r$t$r$t"

This was as short as I could get it without frying my brain. Takes input as $w='coverage'.

Try it online!

\$\endgroup\$
2
2
\$\begingroup\$

Lua, 164 157 bytes

w=arg[1]
i,j,a,b=w:find('[aeiouy]+([^aeiouy]+)(.)')
print(w:sub(1,j-#a)..(('pgtvkhjglmnbqrzdfwxs'):sub(('bcdfghjklmnpqrstvwxz'):find(a:sub(1,1)))..b):rep(2))

Edit 1: Removed 7 bytes by looking for any character after the consonants (see regex)

Try it online!

This program takes a string in CLI argument and prints its covfefied version.

This is my first submission to a code golf! I didn't check the others in detail so I might have missed some common optimizations (and fell in some traps). I used Lua because I've grown to like this little language, and I tried to find a regex that suited my needs.

Here's a cleaner version, using a function (I intended to use one, but the keywords in Lua are too long!):

function covfefy(word)
  i, j, a, b = word:find('[aeiouy]+([^aeiouy]+)(.)')

  -- 'a' is one or several consonants following the first vowel, b is the first vowel after that
  -- 'i' is the index of the beginning of 'a', 'j' the index of 'b'

  cov = word:sub(1, j - #a)

  -- Look for the first letter of 'a' in the voiced/voiceless table
  f = ('pgtvkhjglmnbqrzdfwxs'):sub(('bcdfghjklmnpqrstvwxz'):find(a:sub(1, 1)))

  return cov .. (f .. b):rep(2)
end

Feel free to give some feedback :)

Note: If you're wondering, it's 149 bytes long using MoonScript!

\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES5), 237 229 bytes

function(s){r=['aeiouy','bcdfgkpstvz','pgtvkgbzdfs']i=0,p=''while(p+=s[i],r[0].indexOf(s[i++])<0);while(p+=s[i],~r[0].indexOf(s[i++]));b=s[i-1];while(r[0].indexOf(s[i++])<0);c=r[1].indexOf(b)d=((~c)?r[2][c]:b)+s[i-1]return p+d+d}

Try it online!

Probably not the most golfy, but it is ES5.

Recently fixed a bug. Example output:

creation->creatdidi
coverage->covfefe
example->exxaxa
programming->progkaka
code->codtete
president->preszizi
\$\endgroup\$
2
\$\begingroup\$

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);
        }
    }
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ Jul 22, 2017 at 2:51
  • \$\begingroup\$ @DestructibleLemon Thanks for the tip! \$\endgroup\$ Jul 24, 2017 at 14:18
2
\$\begingroup\$

SmileBASIC, 185 179 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
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ 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! \$\endgroup\$ Mar 10, 2021 at 20:53
  • 2
    \$\begingroup\$ 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! \$\endgroup\$
    – Wheat Wizard
    Mar 10, 2021 at 20:55
  • \$\begingroup\$ Thank you guys for the optimizations! \$\endgroup\$
    – Roy
    Mar 11, 2021 at 21:22
2
\$\begingroup\$

Python 3, 190 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
print(q[:c]+('pgtvkhjglmnbqrzdfwxs'[C.index(q[c-1])]+q[f(q[c:])+c])*2)

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

-4 bytes from using the result of a calculation inline rather than assigning it to a variable (whoops)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Your TIO gives an error. \$\endgroup\$
    – FlipTack
    Jan 4, 2018 at 7:49
  • \$\begingroup\$ @FlipTack turns out I'm just an idiot - "test" is not a valid test string. Updated the link and shaved 4 bytes off of the source \$\endgroup\$
    – osuka_
    Apr 21, 2021 at 5:42
2
\$\begingroup\$

BQN, 79 bytesSBCS

{s∾4⥊("s_xwf_dzrqb_nmlgj_hkv_tgp"⊑˜'z'-⊑⌽s←⊑w⊔𝕩)∾⊑𝕩/˜v∧w←0∾»∨`1‿0⍷v←𝕩∊"aeiouy"}

Run online!

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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}
\$\endgroup\$
1
  • \$\begingroup\$ Welcome to PPCG! \$\endgroup\$ Jun 19, 2017 at 14:46
1
\$\begingroup\$

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

\$\endgroup\$
3
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ Jun 12, 2017 at 23:52
  • \$\begingroup\$ made smaller by unformatting. Could go even smaller, as modern pascal does not enforce the grammer of then a wasted heartbeat in parsing. \$\endgroup\$
    – Ozz Nixon
    Jun 13, 2017 at 17:46
  • 3
    \$\begingroup\$ if you can go even smaller then you should \$\endgroup\$ Jun 13, 2017 at 22:17
1
\$\begingroup\$

Vyxal o, 32 bytes

ðp≬k∪$cḊṘ÷Ḣ₴₴h:₴$hJ«ƛKS⟩NĖ!ǐ«ḂĿd

Try it Online!

Port of Grimmy's 05AB1E answer.

\$\endgroup\$
1
\$\begingroup\$

Knight, 161 154 bytes

;=xP;=v=c=uF;=s"";Wx;|&v c=s+sA=tAx;I=p|?97=aAx|?101a|?105a|?111a|?117a?121a=vTx;I&v!p=cTx;&&p&c&v!u=uAa=xGx 1LxO+s*+G"pgt_vkh_jglmn_bqrzd_fwx_s"-t 98Tu 2

Try it online!

-7 bytes thanks to Aiden Chow

\$\endgroup\$
1
  • \$\begingroup\$ 155 bytes: ;=xP;=v=c=uF;=s"";Wx;|&v c=s+sA=tAx;I=p|?97=aAx|?101a|?105a|?111a|?117a?121a=vTx;I&v!p=cTx;I&p&c&v!u=uAaN=xGx 1LxO+s*+G"pgt_vkh_jglmn_bqrzd_fwx_s"-t 98Tu 2 \$\endgroup\$
    – Aiden Chow
    Aug 15, 2022 at 19:29
1
\$\begingroup\$

brev 149 bytes

(define(v x)(string-translate x"bcdfgkpstvz""pgtvkgbzdfs"))(fn(strse x"(.*?[aeiouy]+(.))[^aeiouy]*(.)"(entire(conc(m 1)(v(m 2))(m 3)(v(m 2))(m 3)))))

Straight-forward regex solution♥

\$\endgroup\$
0
\$\begingroup\$

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)
\$\endgroup\$
0
\$\begingroup\$

Scala, 281 bytes

Modified from the answer of @WaitndSe.


281 bytes version. Try it online!

type S=String
def f(s:S):S={val r,c=new StringBuilder;var(n,w,a)=(0,"aeiouy","bcdfghjklmnpqrstvwxz");for(i<-s){if(n<2)r+=i;if(n<1&&w.contains(i))n= 1;if(n==1&&a.contains(i)){c++="pgtvkhjglmnbqrzdfwxs"(a.indexOf(i))+"";n=2};if(n==2&&w.contains(i)){r++=c+""+i+c+i;return r+""}};r+""}

340 bytes version. Try it online!

type S=String
implicit class V[A](val x:A)extends AnyVal{def Q=x.toString}
def f(s:S):S={val r,c=new StringBuilder;var(n,w,a)=(0,"aeiouy","bcdfghjklmnpqrstvwxz");for(i<-s){if(n<2)r+=i;if(n<1&&w.contains(i))n= 1;if(n==1&&a.contains(i)){c++="pgtvkhjglmnbqrzdfwxs"(a.indexOf(i)).Q;n=2};if(n==2&&w.contains(i)){r++=c.Q+i+c.Q+i;return r.Q}};r.Q}

Ungolfed version. Try it online!

import scala.collection.mutable

object Main {
  def f(s: String): String = {
    val r = new StringBuilder
    var c = ""
    var n = 0
    val w = "aeiouy"
    val a = "bcdfghjklmnpqrstvwxz"

    for (i <- s) {
      if (n < 2) r += i
      if (n < 1 && w.contains(i)) n = 1
      if (n == 1 && a.contains(i)) {
        c = "pgtvkhjglmnbqrzdfwxs"(a.indexOf(i)).toString
        n = 2
      }
      if (n == 2 && w.contains(i)) {
        r ++= c + i + c + i
        return r.toString()
      }
    }
    r.toString()
  }

  def test(func: String => String, testcases: Map[String, String]): Unit = {
    for ((caseInput, caseOutput) <- testcases) {
      if (func(caseInput) != caseOutput) {
        throw new Exception(s"Function fails on testcase '$caseInput'.")
      }
    }
    println("Function passed all testcases.")
  }

  def main(args: Array[String]): Unit = {
    test(f, Map(
      "coverage" -> "covfefe",
      "example" -> "exxaxa",
      "programming" -> "progkaka",
      "code" -> "codtete",
      "president" -> "preszizi"
    ))

    println(f("creation"))
    println(f("coverage"))
    println(f("example"))
    println(f("programming"))
    println(f("code"))
    println(f("president"))
  }
}
\$\endgroup\$
0
\$\begingroup\$

Lua, 128 bytes

w=...i,j,a,b=w:find'[aeiouy]+([^aeiouy]+)(.)'n=a:byte()-97g=('pgtevkhijglmnobqrzdufwxys'):sub(n,n)..b print(w:sub(1,j-#a)..g..g)

Try it online!

This is effectively Kyrio's Answer with a lot of minor optimizations, as well as completely swapping out the logic for finding the replacement consonant.

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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