背景
庆祝Dyalog APL 16.0的发布,该问题的解决方案是{⊢⌺(≢⍵)⊢⍵}
说明
任务
给定具有奇数长度 n的可打印ASCII字符串,使n × n正方形,其中字符串水平居中,重复复制以垂直居中,并且在每行和每列中都具有相同的字符串。请注意,除居中的字符串以外的所有字符串都将被切除,以保持正方形的大小n × n。
您的代码说明将不胜感激。
规则
- 您可能会有尾随空格和换行符(这包括右下三角形)
- 您可以返回字符串列表
使用字符串的示例ABXCD
:
n为5。首先,我们绘制两个居中的字符串,一个水平和一个垂直:
┌─────┐ │A│ │B│ │ABXCD│ │C│ │D│ └─────┘
(为清晰起见,添加了5×5边界框)
然后,我们水平和垂直放置所有可能的杂技:
一种 AB ┌─────┐ │ABX│CD │ABXC│D │ABXCD│ A│BXCD│ AB│XCD│ └─────┘ 光盘 d
最后,我们只返回边界框内的内容:
ABX ABXC ABXCD BXCD XCD
测试用例
World
:
Wor
Worl
World
orld
rld
mississippi
:
missis
mississ
mississi
mississip
mississipp
mississippi
ississippi
ssissippi
sissippi
issippi
ssippi
Pneumonoultramicroscopicsilicovolcanoconiosis
:
Pneumonoultramicroscopi
Pneumonoultramicroscopic
Pneumonoultramicroscopics
Pneumonoultramicroscopicsi
Pneumonoultramicroscopicsil
Pneumonoultramicroscopicsili
Pneumonoultramicroscopicsilic
Pneumonoultramicroscopicsilico
Pneumonoultramicroscopicsilicov
Pneumonoultramicroscopicsilicovo
Pneumonoultramicroscopicsilicovol
Pneumonoultramicroscopicsilicovolc
Pneumonoultramicroscopicsilicovolca
Pneumonoultramicroscopicsilicovolcan
Pneumonoultramicroscopicsilicovolcano
Pneumonoultramicroscopicsilicovolcanoc
Pneumonoultramicroscopicsilicovolcanoco
Pneumonoultramicroscopicsilicovolcanocon
Pneumonoultramicroscopicsilicovolcanoconi
Pneumonoultramicroscopicsilicovolcanoconio
Pneumonoultramicroscopicsilicovolcanoconios
Pneumonoultramicroscopicsilicovolcanoconiosi
Pneumonoultramicroscopicsilicovolcanoconiosis
neumonoultramicroscopicsilicovolcanoconiosis
eumonoultramicroscopicsilicovolcanoconiosis
umonoultramicroscopicsilicovolcanoconiosis
monoultramicroscopicsilicovolcanoconiosis
onoultramicroscopicsilicovolcanoconiosis
noultramicroscopicsilicovolcanoconiosis
oultramicroscopicsilicovolcanoconiosis
ultramicroscopicsilicovolcanoconiosis
ltramicroscopicsilicovolcanoconiosis
tramicroscopicsilicovolcanoconiosis
ramicroscopicsilicovolcanoconiosis
amicroscopicsilicovolcanoconiosis
microscopicsilicovolcanoconiosis
icroscopicsilicovolcanoconiosis
croscopicsilicovolcanoconiosis
roscopicsilicovolcanoconiosis
oscopicsilicovolcanoconiosis
scopicsilicovolcanoconiosis
copicsilicovolcanoconiosis
opicsilicovolcanoconiosis
picsilicovolcanoconiosis
icsilicovolcanoconiosis
致谢
多亏了dzaima,Leaky Nun和Xcoder先生完成了本次挑战的所有构想。