18
\$\begingroup\$

Y'know, we've had a lot of "alphabet" challenges recently. (one two three four five.) While I love a good challenge, and those challenges were very fun, I think it's time for a change of pace. We need to exclude such challenges in the future. It's time for automation!

You're going to find some alphabets for me, and for automation (and for glory!) Alphabets are tricky and like to disguise themselves.[citation-needed] You'll need to account for the following factors:

  1. Alphabets can be uppercase or lowercase (but not both). So, you need to look for ABCDEFGHIJKLMNOPQRSTUVWXYZ and abcdefghijklmnopqrstuvwxyz, but not AbCdeFGhIJkLmNOpQRsTuvwxyZ. That is, only look for alphabets that are composed of entirely one case.
  2. Alphabets can shift around. they may not always start with A, but instead may start with G or U. So you'll have to look for things like OPQRSTUVWXYZABCDEFGHIJKLMN.
  3. Alphabets may not always read forwards. They can also read backwards, up, and down. E.g., ZYXWVUTSRQPONMLKJIHGFEDCBAis also a valid alphabet.

Here's an example of a string that has an alphabet:

JIHGFEDCBAZYXWVUTSRQPONMLK

This is a backwards-oriented, shifted alphabet:

JIHGFEDCBAZYXWVUTSRQPONMLK
<--------|<---------------

This also contains an alphabet:

F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
A
B
C
D
E

it's a down-oriented alphabet:

F |
G |
H |
I |
J |
K |
L |
M |
N |
O |
P |
Q |
R |
S |
T |
U |
V |
W |
X |
Y |
Z V
A===
B |
C |
D |
E V

Your challenge is to write a program, function, etc. that, given a string, outputs/returns a truthy value if the string contains at least one alphabet, or a falsey value otherwise. This is a , so the shortest program in bytes wins.

Test cases

Truthy

ABCDEFGHIJKLMNOPQRSTUVWXYZ

abcdefghijklmnopqrstuvwxyz

ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxyz

ZABCDEFGHIJKLMNOPQRSTUVWXYghijklmnopqrstuvwxyzabcdef

ZBCDEFGHIJghijklmnopqrstuvwxyzabcdef

AAAAAAAA
BBBBBBBB
CCCCCCCC
DDDDDDDD
EEEEEEEE
FFFFFFFF
GGGGGGGG
HHHHHHHH
IIIIIIII
JJJJJJJJ
KKKKKKKK
LLLLLLLL
MMMMMMMM
NNNNNNNN
OOOOOOOO
PPPPPPPP
QQQQQQQQ
RRRRRRRR
SSSSSSSS
TTTTTTTT
UUUUUUUU
VVVVVVVV
WWWWWWWW
XXXXXXXX
YYYYYYYY
ZZZZZZZZ

 J54
 Igeh
 H
 G
 Fzx6
 E
 Dv
 Cvzxc
 Bs
 Adf
 Z
@Yascvf
 Xsf
 W
 Vfas
 Uw
 Te
~S
 R
 Qasdfasdf
 P
 O
 N
 M
 LMNOPQR
 K

Falsey

Hello, World!

KLMNOPQRSTUVWXYZABCDEF

K        ZYXW
 L         V
  M       U
   N     T
    O   S
     P R
      Q

A
 BCDEFGHIJKLMNOPQRSTUVWXYZ

ABCDEFGHIJKLmnopqrstuvwxyz
\$\endgroup\$
  • 16
    \$\begingroup\$ "I'm sick of alphabet challenges. Here's an alphabet challenge." lol +1 \$\endgroup\$ – AdmBorkBork Aug 9 '16 at 20:26
  • \$\begingroup\$ Can we have the input be padded with spaces to form a rectangle? :3 \$\endgroup\$ – Downgoat Aug 9 '16 at 21:18
  • \$\begingroup\$ @Downgoat Yes, you can. \$\endgroup\$ – Conor O'Brien Aug 9 '16 at 21:20
  • \$\begingroup\$ Another challenge to add to your collection. \$\endgroup\$ – Leaky Nun Aug 9 '16 at 23:29
  • 1
    \$\begingroup\$ Can we take a 2D array of strings? Each row would be a line, right-padded with spaces to form a rectangle \$\endgroup\$ – Luis Mendo Aug 10 '16 at 0:43
5
\$\begingroup\$

Jelly, 28 23 22 bytes

1 byte thanks to Dennis.

26RØAṙ;U$;Œl$
;Zẇ@þ¢FS

Try it online!

Takes an array of strings.

\$\endgroup\$
  • 4
    \$\begingroup\$ wat how is jelly always so short .___. \$\endgroup\$ – Downgoat Aug 10 '16 at 0:35
  • \$\begingroup\$ @Downgoat are you Jelly? \$\endgroup\$ – Patrick Roberts Aug 10 '16 at 11:51
  • 2
    \$\begingroup\$ @PatrickRoberts <s>yes</s> no i am goat \$\endgroup\$ – Downgoat Aug 10 '16 at 19:50
2
\$\begingroup\$

Cheddar, 148 bytes

(s,b=65@"90,c?)->(|>27).map(->s has(b=b.slice(1)+b[0])||s has b.lower||(1|>3).map(j->(c=s.lines.turn(j).vfuse)has b||c has b.lower?1:0).sum?1:0).sum

Try it online!

Non-copmeting, 146 132 bytes

This is the exact same as above except map(...?1:0).sum has become any(...).

(s,b=65@"90,c?)->(|>27).any(->s has(b=b.slice(1)+b[0])||s has b.lower||(1|>3).any(j->(c=s.lines.turn(j).vfuse)has b||c has b.lower))

Rather slow but it works ¯\_(ツ)_/¯ . added any function after challenge release date.

The input does not need to be padded with whitespaces. But if an input doesn't work, pad it with whitespaces to make rectangle. The turn function is really finicky and I'm not sure when it works and when it doesn't

Explanation

Loops through all possible cycles of alphabet. On each iteration check if the current cycle of alphabet exists in the string, if not, check if any of the possible rotations of the string have the alphabet.

Ungolfed

(str, a = 65@"90)->
  (|>27).any(->
    str has (a = a.slice(1) + a[0]) ||
    str has a.lower                 ||
    (1|>3).any(j ->
      (c = str.lines.turn(j).vfuse) has a ||
      c has a.lower
    )
  )
\$\endgroup\$
  • \$\begingroup\$ What does c? mean? \$\endgroup\$ – Conor O'Brien Aug 10 '16 at 0:38
  • \$\begingroup\$ @ConorO'Brien c? means optional argument. basically the same as c=nil \$\endgroup\$ – Downgoat Aug 10 '16 at 0:40
  • \$\begingroup\$ Make a competing version, then put this non-competing version at the bottom. \$\endgroup\$ – Leaky Nun Aug 10 '16 at 0:41
  • \$\begingroup\$ @LeakyNun working on it, can't figure out how to without {} though \$\endgroup\$ – Downgoat Aug 10 '16 at 0:42
  • 1
    \$\begingroup\$ any(...) is just map(...?1:0).sum \$\endgroup\$ – Leaky Nun Aug 10 '16 at 0:43
2
\$\begingroup\$

05AB1E, 43 bytes

A‚Duìvy26FÀD}})U|Dø€J)˜vXDgs`rFysk>ˆ}}¯O__

Explanation in short

Get different variations of alphabet (caps, no-caps, reversed, normal) and store in X.

A‚Duìvy26FÀD}})U

Get each row and column of input as a list of strings.

                 |Dø€J)˜

Check each such string if it contains a variation of the alphabet.

                        vXDgs`rFysk>ˆ}}

Sum and double negate, giving 1 for true and 0 for false.

                                       ¯O__

Try it online

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

Python, 182 bytes

Doesn't feel very 'golfed', but ...

import re
a='abcdefghijklmnopqrstuvwxyz'
P,N='|\n'
p=P.join(a[i:]+a[:i] for i in range(26))
p+=P+p[::-1]
p+=P+p.upper()
lambda s:re.search(p,s+N+N.join(map(''.join,zip(*s.split(N)))))

Theory of operation:

First, build a regex pattern combining all the possible alphabets:

p=P.join(a[i:]+a[:i] for i in range(26)) builds a string of all rotations of 'a' joined with '|'. e.g. "abc...z|bcd...za|..."

p+=P+p[::-1] appends a reversed version of itself.

p+=P+p.upper() appends an uppercase version.

Then create a long string combining the original s and a version of s with the columns turned into rows:

N.join(map(''.join,zip(*s.split(N)))) flips the rows and columns, so 'a\nb\nc' becomes 'abc'

return true if the pattern is in the long string.

\$\endgroup\$
  • \$\begingroup\$ Pretty sure you don't need regex to do this; specifically, in checks for substring. \$\endgroup\$ – Leaky Nun Aug 10 '16 at 4:22
  • \$\begingroup\$ @LeakyNun, I was trying to avoid lots of loops over the possible alphabets (rotations, reversals, case). The regex pattern has all the possibilities--using just one loop. Also, the string to search includes the input string in both normal and row-flipped versions, so no looping there either. \$\endgroup\$ – RootTwo Aug 10 '16 at 5:08

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.