58
\$\begingroup\$

I got the spontaneous idea of making a series of challenges of users that have helped and continue to help the PPCG community be an enjoyable place for everyone, or maybe just specifically for me. :P

If you convert Dennis's name to an array of 1s and 0s where each consonant is 1 and each vowel is 0, the array is [1, 0, 1, 1, 0, 1], which is symmetrical. Thus, your challenge is to determine what other names are like this.

Challenge

Given an ASCII string, remove all characters that aren't letters and determine if the configuration of vowels and consonants are symmetrical. y is not a vowel.

Please note that your program does not have to be this type of string itself.

Test Cases

Dennis -> truthy
Martin -> truthy
Martin Ender -> truthy
Alex -> falsy
Alex A. -> truthy
Doorknob -> falsy
Mego -> falsy

Reference Implementation

This Python 3 code will give the correct output given a test case. It is as ungolfed as I could make it without being ridiculous.

Python 3

s = input()
l = []
for c in s:
	if c in 'AEIOUaeiou':
		l.append(0)
	elif c in 'BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz':
		l.append(1)
print(l == list(reversed(l)), end = '')

Try it online!

\$\endgroup\$
  • \$\begingroup\$ When and who is #2? \$\endgroup\$ – caird coinheringaahing Jun 10 '17 at 15:58
  • \$\begingroup\$ @cairdcoinheringaahing Thanks for reminding me. It's going to be about Mego (TNB RO hence the italics) but I haven't gotten around to finalizing it yet. \$\endgroup\$ – HyperNeutrino Jun 10 '17 at 17:08
  • \$\begingroup\$ @cairdcoinheringaahing I'm pretty sure he knows already; I said I'd do one about him but I haven't decided if I'm going to do something relating to penguins or TNB yet. \$\endgroup\$ – HyperNeutrino Jun 10 '17 at 17:32
  • \$\begingroup\$ @HyperNeutrino Umm, you can't use italics in titles. \$\endgroup\$ – Erik the Outgolfer Jun 10 '17 at 18:47
  • \$\begingroup\$ @EriktheOutgolfer Aww :( That sucks. \$\endgroup\$ – HyperNeutrino Jun 11 '17 at 1:20

40 Answers 40

1
2
0
\$\begingroup\$

PowerShell, 87 Bytes

$s=("$args"-replace '\P{L}'-replace'[aeiou]',0-replace'\D',1);$s-eq(-join($s[-1..-99]))

Get a copy of the string where vowels are 0 and consonants are 1, with all special chars removed, compare that string to a reversed version joined back to a string

Output:

PS C:\Users\Connor> "Dennis","Martin","Martin Ender","Alex","Alex A.","Doorknob","Mego" | % {
    $s=("$_"-replace '\P{L}'-replace'[aeiou]',0-replace'\D',1);$s-eq(-join($s[-1..-99]))
}
True
True
True
False
True
False
False
\$\endgroup\$
0
\$\begingroup\$

Retina, 47 bytes

i(`[^a-z]

[aeiou]
1
\D
0
+`^(.)(.*)\1$
$2
^.?$

Try it online!

This is just a different approach for non alphabet chars

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

Google Sheets, 248 bytes

=ArrayFormula(REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(UPPER(A1),"[^A-Z]",""),"[AEIOU]","0"),"[^0]","1")=REGEXREPLACE(REGEXREPLACE(REGEXREPLACE(UPPER(JOIN("",(MID(A1,LEN(A1)-ROW(INDIRECT("1:"&LEN(A1)))+1,1)))),"[^A-Z]",""),"[AEIOU]","0"),"[^0]","1"))

Three nested REGEXREPLACE functions transform it from the original to a string of ones and zeroes. The JOIN function is used to reverse the original string so it's nested into the same REGEXREPLACE functions to transform it to the reverse string of ones and zeroes. It's a nightmare.

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

Perl, 42 bytes

s!(.)\PL*!1+aeiou=~lc$1!ge;$_=$_==reverse

Run with perl -p.

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

Actually, 20 bytes

ù⌠úc⌡░⌠"aeiou"c⌡M;R=

Try it online! (runs all test cases)

-3 bytes from Erik the Outgolfer's suggestion on a different answer

Explanation:

ù⌠úc⌡░⌠"aeiou"c⌡M;R=
ù                     lowercase input
 ⌠úc⌡░                characters where function is truthy:
  úc                    is the character a lowercase letter?
      ⌠"aeiou"c⌡M     for each letter:
       "aeiou"c         does the vowel string contain the letter?
                 ;R=  compare equality with reverse (is it a palindrome?)
\$\endgroup\$
0
\$\begingroup\$

Excel VBA, 115 Bytes

Anonymous VBE immediate window function that takes input from range [A1] and outputs to the VBE immediate window.

For i=1To[Len(A1)]:a=Mid([A1],i,1):b=IIf(Instr(1,"AEIOU",a,1),1,IIf(a Like"[A-Za-z]",0,""))&b:Next:?b=StrReverse(b)
\$\endgroup\$
0
\$\begingroup\$

Kotlin, 75 bytes

filter{it.isLetter()}.map{"aeiou".contains(it,true)}.let{it==it.reversed()}

Beautified

filter { it.isLetter() }.map { "aeiou".contains(it, true) }.let { it == it.reversed() }

Test

data class Test(val input: String, val output: Boolean)

val tests = listOf(
    Test("Dennis",true),
    Test("Martin",true),
    Test("Martin Ender",true),
    Test("Alex",false),
    Test("Alex A.",true),
    Test("Doorknob",false),
    Test("Mego",false)
)

fun String.f() =
filter{it.isLetter()}.map{"aeiou".contains(it,true)}.let{it==it.reversed()}
fun main(args: Array<String>) {
    for ((input, expected) in tests) {
        val actual = input.f()
        if (actual != expected) throw AssertionError()
    }
}

TIO

TryItOnline

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

Julia 0.6, 65 bytes

f(s,b=[c in "aeiouAEIOU" for c in s if isalpha(c)])=b==reverse(b)

Try it online!

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

Pyt, 59 bytes

ɬ←ąĐ0↔ą∈⇹6²Ĩ*ž1ᴇ-5²⁺%⁺+ĐĐĐĐ1=⇹5=⇹04Ș9=06Ș+35*=0↔+37*=∨∨∨∨+₽

Try it online!

Much of this code is because Pyt is not very good at strings.

Explanation:

ɬ               Push "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
←ą              Get input string as an array of characters
Đ               Duplicate the array of characters
0↔              Push 0 and flip the stack
ą               Get the top of the stack as an array of characters
∈               Is each character in the input a letter?
⇹               Swap top two on the stack (input as array of characters)
6²Ĩ             Interpret element-wise as base-36 **
*ž              Remove all non-letters
1ᴇ-             Subtract 10 from each element
5²⁺%            Mod 26
⁺               Increment
+               Let's get rid of that 0
ĐĐĐĐ            Push 4 additional copies of the top of the stack
1=⇹             Is it equal to 1 ('a')
5=⇹04Ș          Is it equal to 5 ('e')
9=06Ș           Is it equal to 9 ('i')
+               Get rid of a 0
35*=            Is it equal to 15 ('o')
0↔              Push 0 and flip the stack
+               Get rid of a 0
37*=            Is it equal to 21 ('u')
∨∨∨∨            OR the arrays
+               Get rid of that last 0
₽               Is the top of the stack a palindrome?
\$\endgroup\$
0
\$\begingroup\$

GolfScript, 34 bytes

{32|}%.123,97>--{"aeiou"?)!}%.-1%=

Try it online!

Explanation

{32|}%                             # Convert to lowercase (Works at least with alpha)
      .123,97>--                   # Keep only lowercase letters
                {"aeiou"?)!}%      # Foreach: is it a vowel?
                             .-1%= # Is it a palindrome?
\$\endgroup\$
1
2

Your Answer

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 or ask your own question.