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)


    • Find the first consonant after that


    • Remove the rest of the string


    That is your first sound group.

    Next step:

    Get the last consonant of the sound group


    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


    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:


    Concatenate this to the first sound group:


    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".

    This specifies one concept of covfefification but I keep feeling that a reference to Douglas Hofstadter's (and Melanie Mitchell's) work on string-conversion analogies, e.g. in *Fluid Concepts* seems appropriate.

    Answers over 140 characters should be disqualified

    Unfortunately it is impossible to do this in TrumpScript :(

    @SandyGifford No, see the list of things to avoid when writing a challenge.

    @ThePlasmaRailgun dude...

    @ThePlasmaRailgun It was a joke, since tweets have to be 140 characters or less.

    It is worth noting that covfefifying a covfefified string will keep it the same.

  • Jelly,  58  57 bytes


    A full program that accepts a list of lowercase characters and prints the result.

    Try it online!


    <TḢị - Link 1, extract first value from y not less than x: number, x; list of numbers, y
    - e.g. 5, [3,4,7]
    < - x less than vectorised across y [0,0,1]
    T - truthy indices [ 3]
    Ḣ - head 3
    ị - index into y 7

    e€Øyµ¬TĖEÐḟḢṪ;ç¥T - Link 2, indices of the letters to manipulate: list of characters, w
    Øy - vowel+ yield = "AEIOUYaeiouy" e.g. "smouching"
    e€ - exists in for €ach letter in w 001100100
    µ - monadic chain separation, call that v
    ¬ - not vectorised across v 110011011
    T - truthy indices 12 56 89
    Ė - enumerate [[1,1],[2,2],[3,5],[4,6],[5,8],[6,9]]
    Ðḟ - filter discard if:
    E - elements are equal [[3,5],[4,6],[5,8],[6,9]]
    Ḣ - head [3,5]
    Ṫ - tail 5
    T - truthy indices of v 34 7
    ¥ - last 2 links as a dyad
    ç - call last link (1) as a dyad 7
    ; - concatenate 5,7
    - ...i.e the indexes of 'c' and 'i'

    ḣÇḢ⁸ÇịµḢØYiị“ßȷ%Hẹrȧq’œ?ØY¤⁾cgy;ẋ2 - Main link: list of characters, w
    - e.g. "smouching"
    Ç - call the last link (2) as a monad [5,7]
    ḣ - head to index (vectorises) ["smouc","smouchi"]
    Ḣ - head "smouc"
    - implicit print due to below leading constant chain
    ⁸ - link's left argument, w
    Ç - call the last link (2) as a monad [5,7]
    ị - index into w "ci"
    µ - monadic chain separation, call that p
    Ḣ - head p 'c'
    ØY - consonant- yield = "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz"
    i - first index 22
    ¤ - nilad followed by link(s) as a nilad:
    “ßȷ%Hẹrȧq’ - base 250 number = 1349402632272870364
    ØY - consonant- yield = "BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz"
    œ? - nth permutation = "BCDFGHJKLMNPQRSTVWXZpctvkhjglmnbqrzdfwxs"
    ị - index into (special case ->) 'c'
    ⁾cg - literal ['c','g']
    y - translate (change 'c's to 'g's) 'g'
    ; - concatenate with the headed p "gi"
    ẋ2 - repeat list twice "gigi"
    - implicit print ...along with earlier = smoucgigi

    This is amazing...

    Incredible work.

    I'm jelly. Upvoted.

    This is the weirdest programming language I've ever seen.

    @Ryan it's intended for golfing.

    I'm learning Jelly currently and this answer is still amazing.

  • JavaScript (ES6), 107 103 bytes

    Saved 4 bytes thanks to GOTO 0


    Test cases

    let f =



    You can save a few bytes like this: `s=>([,a,b,c]=s.match\`(.*?[aeiouy]+(.)).*?([aeiouy])\`,a+(b=(a="bcdfgszkvtgp")[]||b)+c+b+c)`

    @GOTO0 Thanks, updated.

  • Jelly, 45 39 bytes


    Try it online!

    How it works

    e€ØyIi-‘ɓḣ;ç                Main link. Argument: s (string)

    Øy Vowels with y; yield "AEIOUYaeiouy".
    e€ Test each character in s for membership.
    I Increments; compute the forward differences of the
    resulting array of Booleans.
    i- Find the first index of -1.
    ‘ Increment this index to find the index of the first
    consonant that follows a vowel.
    Let's call this index j.
    ɓ Begin a new chain. Left argument: s. Right argument: j
    ḣ Head; yield the first j characters of s.
    ç Call the helper link with arguments s and j.
    ; Concatenate the results to both sides.

    Øa“œṣ$b|0Ḃ’ṃ,Ṛ$yṫµfØyḢṭḢẋ2  Helper link. Left argument: s. Right argument: j

    Øa Alphabet; set the return value to “”.
    “œṣ$b|0Ḃ’ Yield 7787255460949942. This is a numeric literal in
    bijective base 250. The value of each digit matches its
    1-based index in Jelly's code page.
    ṃ Convert 7787255460949942 to base 26, using the digts
    a = 1, b = 2, ..., y = 25, z = 0.
    This yields "bcdfkszgvtgp".
    ,Ṛ$ Pair the result with its reverse, yielding
    ["bcdfkszgvtgp", "pgtvgzskfdcb"].
    ṫ Call tail with arguments s and j, yielding the j-th and
    all following characters of s.
    y Translate the result to the right according to the
    mapping to the left, i.e., replace 'b' with 'p', 'c'
    with 'g', etc. 'g' appears twice in the first string
    of the mapping; only the first occurrence counts.
    Let's call the resulting string r.
    µ Begin a new chain. Argument: r
    fØy Filter; remove non-vowels from r.
    Ḣ Head; take the first vowel.
    Ḣ Head; take the first character/consonant of r.
    ṭ Tack; append vowel to the consonant.
    ẋ2 Repeat the resulting string twice.

    sorry, buddy, looks like you missed out on the mega jelly rep

    tfw an answer looks overly simplistic but is in fact really wonderful...simple is beautiful

  • CJam, 59 58 57 56 bytes

    q_{"aeiouy":V&,_T|:T^}#)/(_W>"cbdfkszgvtpg"_W%[email protected]&0=+_

    Try it online!


    q_                   e# Read the input and copy it.
    { e# Find the index of the first char for which the following is true:
    "aeiouy":V e# Push "aeiouy" and store it in V.
    &, e# Check if the current char is in the vowel string (0 or 1).
    _T|:T e# Copy the result and OR with T (T is initially 0), storing back in T.
    ^ e# XOR with the original result. This will be 1 for the first
    e# consonant appearing after a vowel.
    }# e# (end find)
    )/ e# Increment the index and split the string into chunks of that size.
    ( e# Pull out the first chunk.
    _W> e# Copy it and get the last character (the consonant).
    "cbdfkszgvtpg"_W%er e# Transliterate the consonant to voiced/voiceless alternative.
    @s e# Bring all the other split chunks to the top and join them together.
    V&0= e# First char of the set intersection of that and the vowels.
    e# (i.e. the first vowel in the second half)
    + e# Concatenate the new consonant and the vowel.
    _ e# Duplicate the result of that.
    e# Implicit output of stack contents.

    CJam beats Jelly? :O (At least, it beats the Jelly answer everybody seems to be upvoting.)

  • C, 219 213 206 179 175 bytes

    #define p putchar
    #define q(a)for(;a strchr("aeiouy",*s);p(*s++));
    f(s,c,h)char*s;{q(!)q()p(*s);p(c="pgt vkh jglmn bqrzd fwx s"[*s-98]);p(h=s[strcspn(s,"aeiouy")]);p(c);p(h);}

    Try it online!

    Does *p=putchar work as the first line?

    Sorry disqualified. Can't fit in a tweet.

    @cairdcoinheringaahing you sir are incorrect (I know that it was 140 when you wrote that)

    171 bytes – Try It Online")

    12 or so bytes can be shaved off by replacing `#define`s and the function with preprocessor flags (`-D...`).

    Actually tweetable now because twitter allows 280 chars.

  • Perl 5, 81 72 bytes


    Try it online!

    You and I had the same idea with `\K`, but you did it 9 bytes better than I did. Good answer!

  • PHP, 121 Bytes


    Try it online!

    -2 bytes: `echo$t[1],$z=strtr($t[2].$t[3],bcdfgkpstvz,pgtvkgbzdfs),$z;`

    @Titus I have not think about that. Thank You

    why not rename `$argn` to something shorter? `$a`, for example - that's -3 bytes

    @TylerSebastian I must have an input variable that exists. Yes I can create a function but if I do it it raise the byte count more as use the three bytes

    ah ok sorry I forgot how PHP does command line args - I just saw that you had defined it in the header section but failed to realize it was a reserved variable.

  • Python 3, 155 139 bytes

    import re
    def f(x,k='aeiouy])'):b,c,v=re.findall(f'(.*?[{k}([^{k}.*?([{k}',x)[0];return b+c+(('bcdfgkpstvz'+c)['pgtvkgbzdfs'.find(c)]+v)*2

    removed 16 bytes thanks to @ovs

    removed 1 byte thanks to Gábor Fekete

    You could create a variable which has the value `'aeiouy]'`, maybe that will save some bytes. Also you can remove some characters from the replacement strings as there are the same.

    I can't remove the identical characters from the replacement string, because that would be an `IndexError`, and saving `aeiouy])` doesn't save any bytes.

    if you pull out something like `s='aeiouy])'`, you could use `b,c,v=re.findall('(.*?[%s([^%s.*?([%s'%(s,s,s)`. It's not shorter, but might lead towards a way to shorten it overall.

    yeah, using f-strings it might be shorter

    Who serially upvoted comments?

    Using f-strings will save 1 byte: `k='aeiouy])'` and `f'(.*?[{k}([^{k}.*?([{k}'`

  • Java 8, 243 236 222 bytes

    s->{String q="[a-z&&[^aeiouy]]",a=s.replaceAll("(^"+q+"*[aeiouy]+"+q+").*","$1"),b="pgtvkhjglmnbqrzdfwxs".charAt("bcdfghjklmnpqrstvwxz".indexOf(a.charAt(a.length()-1)))+s.replaceAll(a+q+"*([aeiouy]).*","$1");return a+b+b;}

    Uses .replaceAll regexes with capture groups to filter out the parts we don't want.


    Try it here.

    s->{ // Method with String parameter and String return-type
    // Temp String we use multiple times:
    String q="[a-z&&[^aeiouy]]",
    // Regex to get the first part (i.e. `creation` -> `creat` / `example` -> `ex`)
    // Get the trailing consonant and convert it
    // Get the next vowel after the previous consonant from the input-String
    // Return the result:
    return a+b+b;
    } // End of method

  • Pyth, 54 bytes

    L+hb?>F}RJ"aeiouy"<b2+hKtb*2+XhK"cgdsfbpvztkg")[email protected]

    This defines a function y, that expects a string.
    Try it online: Test Suite

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM

Tags used