35
Background
Celebrating the release of Dyalog APL 16.0, where the solution to this problem is {⊢⌺(≢⍵)⊢⍵}
Explanation
Task
Given a printable ASCII string of odd length n, make an n × n square with the string centered horizontally, duplicated to be centered vertically, and with acrostics of the same string in each row and column. Note that all but the centered strings will be cut off to keep the square's size n × n.
Explanation of your code will be much appreciated.
Rules
- You may have trailing whitespace and newlines (this includes the lower-right triangle)
- You may return a list of strings
Example using the string ABXCD
:
n is 5. First we draw the two centered strings, one horizontal and one vertical:
┌─────┐ │ A │ │ B │ │ABXCD│ │ C │ │ D │ └─────┘
(5 × 5 bounding box added for clarity)
Then we place all the possible acrostics, horizontally and vertically:
A AB ┌─────┐ │ ABX│CD │ ABXC│D │ABXCD│ A│BXCD │ AB│XCD │ └─────┘ CD D
Finally, we return only what is inside the bounding box:
ABX ABXC ABXCD BXCD XCD
Test cases
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
Acknowledgements
Thanks to dzaima, Leaky Nun, Mr. Xcoder for everything but the very idea of this challenge.
1Do the spaces-triange on the bottom right have to be included or not? – flawr – 2017-07-03T14:21:08.253
1@flawr OP: may – Adám – 2017-07-03T15:20:29.690