# 单词搜索助手

12

（免责声明：以上报道可能不太准确。）

``````ABCDE
FGHIJ
KLMNO
PQRST
``````

``````ABCDE FGHIJ KLMNO PQRST
E DJ CIO BHNT AGMS FLR KQ P
EJOT DINS CHMR BGLQ AFKP
T OS JNR EIMQ DHLP CGK BF A
TSRQP ONMLK JIHGF EDBCA
P QK RLF SMGA TNHB OIC JD E
PKFA QLGB RMHC SNID TOJE
A FB KGC PLHD QMIE RNJ SO T
``````

Denker

@DigitalTrauma：不，不是真的-这个根本不要求您找到任何单词。
Deusovi'3

4

## Python 3，181字节

``````def f(s):
for k in [1,0]*4:
b=list(zip(*[([' ']*(len(s)-1-n)*k+list(i)+[' ']*n*k)[::-1] for n,i in enumerate(s)]))
print([' '.join(i).replace(' ','') for i in b])
if k==0:s=b
``````

## 说明

``````def f(s):
for k in [0]*4:                  # loop 4 times, we don't need the index so [0]*4 is shorter than range(4)
l=len(s)-1                      # number of line

# rotation of 45°
a=[(['.']*(l-n)+list(i)+['.']*n)[::-1] for n,i in enumerate(s)]
# tranform matrice :
#  ABC      ..ABC      CBA..
#  DEF  --> .DEF.  --> .FED.
#  GHI      GHI..      ..IHG
b=list(zip(*a))                 # transpose
#  CBA..      C..
#  .FED.  --> BF.
#  ..IHG      AEI
#             .DH
#             ..G
print(' '.join(''.join(i).replace('.','') for i in b))

# rotation of 90°
a=[(list(i))[::-1] for n,i in enumerate(s)]
# tranform matrice :
#  ABC      CBA
#  DEF  --> FED
#  GHI      IHG
b=list(zip(*a))                 # transpose
#  CBA       CFI
#  FED   --> BEH
print(' '.join(''.join(i) for i in b))
s=b
``````

## 结果

``````>>> f(['ABCDE','FGHIJ','KLMNO','PQRST'])
['E', 'DJ', 'CIO', 'BHNT', 'AGMS', 'FLR', 'KQ', 'P']
['EJOT', 'DINS', 'CHMR', 'BGLQ', 'AFKP']
['T', 'OS', 'JNR', 'EIMQ', 'DHLP', 'CGK', 'BF', 'A']
['TSRQP', 'ONMLK', 'JIHGF', 'EDCBA']
['P', 'QK', 'RLF', 'SMGA', 'TNHB', 'OIC', 'JD', 'E']
['PKFA', 'QLGB', 'RMHC', 'SNID', 'TOJE']
['A', 'FB', 'KGC', 'PLHD', 'QMIE', 'RNJ', 'SO', 'T']
['ABCDE', 'FGHIJ', 'KLMNO', 'PQRST']

>>> f(['ABCDEF','GHIJKL','MNOPQR','STUVWX'])
['F', 'EL', 'DKR', 'CJQX', 'BIPW', 'AHOV', 'GNU', 'MT', 'S']
['FLRX', 'EKQW', 'DJPV', 'CIOU', 'BHNT', 'AGMS']
['X', 'RW', 'LQV', 'FKPU', 'EJOT', 'DINS', 'CHM', 'BG', 'A']
['XWVUTS', 'RQPONM', 'LKJIHG', 'FEDCBA']
['S', 'TM', 'UNG', 'VOHA', 'WPIB', 'XQJC', 'RKD', 'LE', 'F']
['SMGA', 'TNHB', 'UOIC', 'VPJD', 'WQKE', 'XRLF']
['A', 'GB', 'MHC', 'SNID', 'TOJE', 'UPKF', 'VQL', 'WR', 'X']
['ABCDEF', 'GHIJKL', 'MNOPQR', 'STUVWX']
``````

``````j=' '.join
def f(s):
for k in [1,0]*4:
b=list(zip(*[([' ']*(len(s)-1-n)*k+list(i)+[' ']*n*k)[::-1] for n,i in enumerate(s)]))
print(j(j(i).replace(' ','') for i in b))
if k==0:s=b
``````

``````>>> f(['ABCDE','FGHIJ','KLMNO','PQRST'])
E DJ CIO BHNT AGMS FLR KQ P
EJOT DINS CHMR BGLQ AFKP
T OS JNR EIMQ DHLP CGK BF A
TSRQP ONMLK JIHGF EDCBA
P QK RLF SMGA TNHB OIC JD E
PKFA QLGB RMHC SNID TOJE
A FB KGC PLHD QMIE RNJ SO T
ABCDE FGHIJ KLMNO PQRST
``````

CalculatorFeline

@CatsAreFluffy我加在解释一个步骤

CalculatorFeline

@CatsAreFluffy ^^好吧，我认为很明显英语不是我的母语
Erwan

Timtech '16

1

# MATL，40字节

``````t!tP!tP!GXKZyqXI"IZ}w_w2\$:"K@2\$Xd!]K!XKx
``````

``````['ABCDE'; 'FGHIJ'; 'KLMNO'; 'PQRST']
``````

``````t          % input 2D char array. Duplicate. The original copy will produce
% the words left to right when displayed
!          % transpose. This will produce the words up to down
tP!        % duplicate, flip upside down, transpose. This will produce the
% words right to left
tP!        % Same. This will produce the words down to up
GXK        % push input again. Copy to clipboard K
Zy         % get size (length-2 vector; [4 5] in the example)
q          % decrement by 1 (gives  [3 4] in the example)
XI         % copy to clipboard I
"          % loop: do this twice, consuming the decremented length-2 vector
I        %   push decremented size vector again
Z}       %   split into its two elements (pushes 3 and 4 in the example)
w_w      %   swap, negave, swap (results in -3, 4 in the example)
2\$:      %   binary range: indices of diagonals  ([-3 -2 -1 0 1 2 3 4]
%   in the first iteration in the example, [-4 -3 -2 -1 0 1 2 3]
%   in the second)
"        %   for each
K      %     push input (first iteration) or its tranposed version (second)
@      %     push index of diagonal
2\$Xd!  %     extract that diagonal as a row vector
]        %   end for each
K!XKx    %   update clipboard K with transposed version for next iteration
% end loop. Display
``````