8
\$\begingroup\$

Based on this challenge, you must determine if a string is covfefey, that is, could it have been produced as output from a covfefifier?

The string will be composed of only alphabet chars (^[a-z]\*$, ^[A-Z]\*$ are possible schemes for input. change the regexs appropriately if using caps)

To do this, there are a few checks you must do:

Do the last four characters follow this scheme:

([^aeiouy][aeiouy])\1

example:

fefe

follows this scheme.

is this consonant at the start of the ending the voiced or voiceless version of a consonant immediately before it?

consonant pairings follow this key. find the consonant occuring before the end part consonant we had, and check whether the end part consonant is there

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

does the first part of the word, the part that does not include the ([^aeiouy][aeiouy])\1, follow this regex:

[^aeiouy]*[aeiouy]+[^aeiouy]

That is, does it contain one group of vowels, and exactly one consonant after that vowel?

If it fulfills all these criteria, it is covfefey.

Output a truthy value if covfefey, otherwise falsy

Test cases

covfefe -> truthy
barber  -> falsy
covefefe -> falsy
pressisi -> falsy
preszizi -> truthy
prezsisi -> truthy
president covfefe -> You don't need to handle this input as it contains a space.
cofvyvy -> truthy
businnene -> falsy (the first part does not follow the regex)
\$\endgroup\$
8
  • \$\begingroup\$ the logical followup to this question is is it covfefey-ey, which outputs if it follows the contruction of covfefey \$\endgroup\$ Jun 1, 2017 at 3:18
  • 1
    \$\begingroup\$ You should use proper formatting, grammar and spelling in your posts. Just btw :P \$\endgroup\$
    – MD XF
    Jun 1, 2017 at 3:35
  • \$\begingroup\$ So we have to capitalize "truthy"/"falsy" iff the input starts with p? \$\endgroup\$ Jun 1, 2017 at 3:38
  • \$\begingroup\$ @CalculatorFeline "Output a truthy value if covfefey, otherwise falsy" \$\endgroup\$ Jun 1, 2017 at 3:40
  • \$\begingroup\$ @Arnauld yes it may return null or false \$\endgroup\$ Jun 1, 2017 at 5:41

5 Answers 5

5
\$\begingroup\$

JavaScript (ES6), 109 108 bytes

Returns true for covfefey / null or false otherwise.

s=>(m=s.match`^[^aeiouy]*[aeiouy]+(.)((.)[aeiouy])\\2$`)&&((a="bcdfgszkvtgp")[11-a.search(b=m[1])]||b)==m[3]

Test cases

let f =

s=>(m=s.match`^[^aeiouy]*[aeiouy]+(.)((.)[aeiouy])\\2$`)&&((a="bcdfgszkvtgp")[11-a.search(b=m[1])]||b)==m[3]

;[
  "covfefe",
  "barber",
  "covefefe",
  "pressisi",
  "preszizi",
  "prezsisi",
  "cofvyvy",
  "exxaxa"
]
.map(s => console.log(s, '-->', f(s)))

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

Jelly, 56 bytes

5ịØYiị“ßȷ%Hẹrȧq’œ?ØY¤⁾cgy
Ṛµ4,2ị=ÇȦ
Çȧe€ØyµḄ%⁴⁼5ȧŒgLe5,6

A monadic link taking a list of lowercase characters and returning 1 for truthy and 0 for falsey.

Try it online! or see the test suite.

How?

5ịØYiị“ßȷ%Hẹrȧq’œ?ØY¤⁾cgy - Link 1, convert 5th character: list of characters, r
5ị                        - index into r at 5
  ØYi                     - first index of that in "BCDF...XZbcdfghjklmnpqrstvwxz"
                    ¤     - nilad followed by link(s) as a nilad:
      “ßȷ%Hẹrȧq’          -   base 250 number = 1349402632272870364
                  ØY      -   yield consonants-y = "BCDF...XZbcdfghjklmnpqrstvwxz"
                œ?        -   nth permutation    = "BCDF...XZpctvkhjglmnbqrzdfwxs"
     ị                    - index into that (converts a 'b' to a 'p' etc..)
                     ⁾cg  - literal ['c','g']
                        y - translate (convert a 'c' to a 'g' - a special case)

Ṛµ4,2ị=ÇȦ - Link 2, check the 3 consonants at the end: list of characters, w
Ṛ         - reverse w
 µ        - monadic chain separation, call that r
  4,2     - 4 paired with 2 = [4,2]
     ị    - index into r
       Ç  - call the last link (1) as a monad (get 5th char converted)
      =   - equal? (vectorises)
        Ȧ - any and all (0 if empty or contains a falsey value, else 1)

Çȧe€ØyµḄ%⁴⁼5ȧŒgLe5,6 - Main link: list of characters, w
Ç                    - call last link as a monad (1 if the 3 consonants are good; else 0)
    Øy               - vowel+y yield = "AEIOUYaeiouy"
  e€                 - exists in? for €ach c in r
 ȧ                   - logical and (list of isVowels; or 0 if link 2 returned 0)
      µ              - monadic chain separation, call that v
       Ḅ             - convert from binary (0 yields 0)
         ⁴           - literal 16
        %            - modulo (0 yields 0)
          ⁼5         - equals 5? (1 if ending is consonant,vowel,consonant,vowel; else 0)
             Œg      - group runs of v (e.g. [0,0,0,1,1,0,1,0,1]->[[0,0,0],[1,1],[0],[1],[0],[1]])
            ȧ        - logical and (the grouped runs if AOK so far, else 0)
               L     - length (number of runs)
                 5,6 - 5 paired with 6 = [5,6]
                e    - exists in (the number of runs must be 5 or 6 to comply)
\$\endgroup\$
5
\$\begingroup\$

Java 8, 211 210 166 163 161 156 bytes

s->{int l=s.length()-5;return"bpbdtdfvfgkgszshhjjllmmnnqqrrwwxxcg".contains(s.substring(l,l+2))&s.matches("[^x]*[x]+(.)((.)[x])\\2".replace("x","aeiouy"));}

-2 bytes by replacing the regex [^x]*[x]+[^x]([^x][x])\\1 with [^x]*[x]+(.)((.)[x])\\2 thanks to @Arnauld's JavaScript answer.

Explanation:

Try it here.

s->{                   // Method with String parameter and boolean return-type
  int l=s.length()-5;  //  Temp integer value with the length of the input-String - 5
  return"bpbdtdfvfgkgszshhjjllmmnnqqrrwwxxcg".contains(s.substring(l,l+2))
                       //   Return if the correct pair is present at the correct location
                       //    (i.e. `vf` at index l-5 + l-6 in the String `convfefe`
   &s.matches("[^x]*[x]+(.)((.)[x])\\2".replace("x","aeiouy"));
                       //    and if the String matches the regex-pattern
}                      // End of method
\$\endgroup\$
4
\$\begingroup\$

Perl, 80 bytes

$_=/[aeiouy]+(*COMMIT)(.)((.)[aeiouy])\2$/&&$3eq$1=~y/bcdfgkpstvz/pgtvkgbzdfs/r

Run with perl -pe.

Due to their length, it’s not often that I get to use the exotic regex verbs in golf, but this challenge is a perfect fit!

Whenever the engine backtracks to (*COMMIT), the entire match fails. This guarantees that the part that comes before it, [aeiouy]+, can only ever match the first thing it tries to match, namely the first continuous stretch of vowels. Thus, [aeiouy]+(*COMMIT)(.) is equivalent to ^[^aeiouy]*[aeiouy]+([^aeiouy]) (equivalent in terms of which strings match, but matches are on different positions).

\$\endgroup\$
4
\$\begingroup\$

PHP , 121 Bytes

$v=aeiouy;echo preg_match("#^[^$v]*[$v]+([^$v])(([^$v])[$v])\\2$#",$argn,$t)&$t[3]==strtr($t[1],bcdfgkpstvz,pgtvkgbzdfs);

Try it online!

\$\endgroup\$

Your Answer

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

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