Goal
Write a function or a program that when given a string, for example "The quick brown fox jumps over the lazy dog"
, outputs:
T h e q u
i
e r t h e c
v k
o l
a b
s z r
p y o
m g o d w
u n
j x o f
Rules
You may not truncate the input!
The output must be text and formatted as above.
The hexagons must have the shortest possible side length. This is wrong for example:
T h e q u i c l a z y d k e o h g b t r o r w e n v o f o s p m u j x
The outer hexagon above has a side of 7 characters, but clearly it is not optimal. A spiral with an outer hexagon with a side of 6 characters would be able to store all the characters of the string too (as shown previously).
The spiral must look like an Archimedean spiral:
- This is not correct:
T h e q u i e r t h e c v k o l g a b s o d y z r p o m w u n j x o f
- This is not correct:
You may start the spiral at any point you like and even go anti-clockwise. Any of these would be valid:
. . . . . . . . . . . . u q e h T . . . . i x j u m p . j u m p s . c e h t r e o s . o T k v f a z y . x y d o v h l . . . . o l d o T o z g e e b a . . n g o v h f a . . r r z . . . s w e e e l q o y . p o h t r n e h t u w d o g m r q w i n u b k c i u o r b k c f o x j
The dots (
'.'
) indicate "cells" that weren't used. You don't have to include them.It does not matter if the string is not long enough to form a complete spiral, but the rules above must still hold.
This is code-golf (no loopholes!), so the shortest answer in terms of bytes wins!
More examples
Note that there are more than one valid outputs due to rule 5.
ABCDE
\$\rightarrow\$
A B
C
E D
#####################################################
\$\rightarrow\$
# # # # # #
#
# # # # # # #
# # #
# # # # # # #
# # # # #
# # # # # #
# # # #
# # # # # #
# #
# # # # # #
0123456789ABCDEF
\$\rightarrow\$
0 1 2 3
4
5
F 6
E 7
D 8
C B A 9
-\\\|///-----\\\|/-----\|/---\---
\$\rightarrow\$
-
\
- - - - - \
/ \ \
| - - - | |
\ \ / /
\ - - - /
\ /
- - - - -
Racecar, racecar!
\$\rightarrow\$
c e c a
R a r
a r !
c ,
e c a r