33
\$\begingroup\$

An alphadrome is a word in which each letter in the first half of the word "reflects" its alphabetical "opposite" in the second half of the word. Write a program or function that returns truthy if the given word is an alphadrome and falsey otherwise.

For example, BEEB is a palindrome. Its first letter B "reflects" its last letter B, and its second letter E reflects its second-to-last letter E.

In contrast, BEVY is an alphadrome. Its first letter B is the second letter of the alphabet, and it reflects the word's last letter Y, which is the second-to-last letter of the alphabet. Likewise, its second letter E is the 5th letter of the alphabet, and it reflects V, the 5th-from-the-end letter of the alphabet.

Like palindromes, an alphadrome can have an odd number of letters, too. WORLD is an alphadrome. W is the 4th-from-the-end letter of the alphabet and D is the 4th letter; O is the 12th-from-the-end letter of the alphabet and L is the 12th letter. The center R reflects itself.

Any single-letter word is an alphadrome.

Rules

Test cases

A        true
ABA      false
ABZ      true
ABBA     false
BEVY     true
GOLF     false
ZOLA     true
WIZARD   true
BIGOTRY  true
RACECAR  false
ABCDEFGHIJKLMNOPQRSTUVWXYZ  true
\$\endgroup\$
13
  • 1
    \$\begingroup\$ Related: Atbash Self Palindromes \$\endgroup\$
    – Jordan
    Commented Oct 12, 2022 at 15:58
  • 4
    \$\begingroup\$ Google returns only 9 results for alphadrome and one of them is this page. \$\endgroup\$
    – chunes
    Commented Oct 13, 2022 at 8:25
  • 11
    \$\begingroup\$ I'm not sure why single-letter inputs are alphadromes; isn't, e.g. the alphabetic reflection of A equal to Z, and "A" doesn't equal "Z"? \$\endgroup\$ Commented Oct 13, 2022 at 14:10
  • 3
    \$\begingroup\$ @97.100.97.109 Fair point, but if you disqualify single-letter words then you must also disqualify all words with an odd number of letters, and I didn't want to do that. \$\endgroup\$
    – Jordan
    Commented Oct 13, 2022 at 16:30
  • 2
    \$\begingroup\$ @TobySpeight You’ve lost me. The question doesn’t specify anything about encoding. \$\endgroup\$
    – Jordan
    Commented Oct 14, 2022 at 13:48

37 Answers 37

1
2
2
\$\begingroup\$

><>, 17 15 bytes

Saved 2 bytes thanks to Jo King

l<*=""+{$n?(3

Try it online

Explanation

l<                # initialize as truthy (length of the input) and reverse direction
l        n?(3     # output when the stack holds at most 1 letter (if odd)
      +{$         # add the first and unhandeled letter
   =""            # compare with 155
  *               # multiply with current truthy/false value
\$\endgroup\$
2
  • \$\begingroup\$ You can use the raw charcode 155 to save a byte over KP+, and you can reverse the program to save another (if you don't mind the truthy value becoming the length of the program) Try it online! \$\endgroup\$
    – Jo King
    Commented Nov 9, 2022 at 8:36
  • \$\begingroup\$ @JoKing Ah, that reversal is brilliant :) Thanks! \$\endgroup\$
    – Emigna
    Commented Nov 9, 2022 at 10:27
1
\$\begingroup\$

Knight (v2), 52 bytes

;=tT;=n/L=pP2;W+1=n-nT=t&?155+A Gp nT A Gp--LpTnTtOt

Try it online!

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

Desmos, 59 bytes

k=l.length
f(l)=∏_{n=1}^{k/2-.5}0^{(155-l[n]-l[k-n+1])^2}

Try It On Desmos!

Try It On Desmos! - Prettified

Takes in a list of codepoints because Desmos doesn't support strings.

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

jq, 54 bytes

Using recursion (54 bytes)

def f:length<2or(.[1:-1]|f)and.[0]+last==155;explode|f

Try it online!

Using mappings (55 bytes)

explode|[.,reverse]|[transpose[]|add==155,true]|sort[1]

Try it online!

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

Pushy, 16 bytes

L2/:{+v;O155K=P#

Try it online!

L2/:                 \ floor(length/2) times do:
    {                \    Cyclic shift the stack left
     +               \    Add the top two items
      v;             \    More the result to the second stack.
        O            \ Go to the second stack
         155         \ Push 155
            K=       \ Check equality in place, replacing every stack element with 0 or 1
              P#     \ Print the product of these
\$\endgroup\$
1
\$\begingroup\$

C (101 bytes)

a;main(z,s)char**s;{int l=strlen(s[1])-1;while(l/2>a)if(s[1][a]-65^90-s[1][l-a++])exit(0);puts("1");}
\$\endgroup\$
1
\$\begingroup\$

Thunno 2, 6 bytes

Ḳ+ṇ6oḣ

Try it online!

Output with inverted booleans. Add the ! flag to take the logical NOT.

Port of Kevin Cruijssen's 05AB1E answer.

Explanation

Ḳ+ṇ6oḣ  # Implicit input
Ḳ+      # Bifurcate and add
  ṇ6o   # Remove 155s
     ḣ  # Remove the first item
        # Implicit output
\$\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.