I've been alphabet hunting for a while

18

1

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

Conor O'Brien

Posted 2016-08-09T20:24:03.677

Reputation: 36 228

16"I'm sick of alphabet challenges. Here's an alphabet challenge." lol +1 – AdmBorkBork – 2016-08-09T20:26:35.470

Can we have the input be padded with spaces to form a rectangle? :3 – Downgoat – 2016-08-09T21:18:01.790

@Downgoat Yes, you can. – Conor O'Brien – 2016-08-09T21:20:26.070

Another challenge to add to your collection. – Leaky Nun – 2016-08-09T23:29:47.650

1Can we take a 2D array of strings? Each row would be a line, right-padded with spaces to form a rectangle – Luis Mendo – 2016-08-10T00:43:18.670

@LuisMendo Sure. – Conor O'Brien – 2016-08-10T00:59:56.040

Answers

5

Jelly, 28 23 22 bytes

1 byte thanks to Dennis.

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

Try it online!

Takes an array of strings.

Leaky Nun

Posted 2016-08-09T20:24:03.677

Reputation: 45 011

4wat how is jelly always so short .___. – Downgoat – 2016-08-10T00:35:01.980

@Downgoat are you Jelly? – Patrick Roberts – 2016-08-10T11:51:35.520

2@PatrickRoberts <s>yes</s> no i am goat – Downgoat – 2016-08-10T19:50:24.147

2

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
    )
  )

Downgoat

Posted 2016-08-09T20:24:03.677

Reputation: 27 116

What does c? mean? – Conor O'Brien – 2016-08-10T00:38:08.523

@ConorO'Brien c? means optional argument. basically the same as c=nil – Downgoat – 2016-08-10T00:40:45.700

Make a competing version, then put this non-competing version at the bottom. – Leaky Nun – 2016-08-10T00:41:29.680

@LeakyNun working on it, can't figure out how to without {} though – Downgoat – 2016-08-10T00:42:36.607

1any(...) is just map(...?1:0).sum – Leaky Nun – 2016-08-10T00:43:16.237

@LeakyNun oh, yeah! of course – Downgoat – 2016-08-10T00:44:48.233

@LeakyNun done! – Downgoat – 2016-08-10T00:48:17.953

.sum?1:0 is just .sum – Leaky Nun – 2016-08-10T00:58:11.363

Why do you use b above but a below? – Leaky Nun – 2016-08-10T01:01:13.847

@LeakyNun I'm doing bool||ar.sum meaning I'll need to convert the first bool into a number if that's the one that's true. I use a below because a for alphabet makes more sense than b – Downgoat – 2016-08-10T01:03:30.177

Your TIO link is very updated – Leaky Nun – 2016-08-10T01:04:03.063

By the way, it would not work for ABCDEFGHIJKLmnopqrstuvwxyz – Leaky Nun – 2016-08-10T01:04:19.300

@LeakyNun :( that means my golf won't work... oh well back to 148 bytes – Downgoat – 2016-08-10T01:12:24.053

I think it would save some bytes if you map the unturned together with the turned. – Leaky Nun – 2016-08-11T03:06:20.960

2

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

Emigna

Posted 2016-08-09T20:24:03.677

Reputation: 50 798

0

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.

RootTwo

Posted 2016-08-09T20:24:03.677

Reputation: 1 749

Pretty sure you don't need regex to do this; specifically, in checks for substring. – Leaky Nun – 2016-08-10T04:22:45.640

@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. – RootTwo – 2016-08-10T05:08:59.143