4 of 8
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
A cube of text ݀
Last time you made a square of text, but now, can you make a cube of text?
The Challenge
Given a string, output the string in the form of a cube.
You can assume the string will always have 2 chars or more, and will only have printable ascii characters.
How to Make a Text Cube
terrible mspaint skills.png http://image.prntscr.com/image/f98aa49da9c14d3ba7866b8fe16ced7a.png
Test Cases
Input:
Test
Output:
Test
e ss
s e e
tseT T
s e e
e ss
Test
Input:
Hello, world!
Output:
Hello, world!
e dd
l l l
l r r
o o o
, w w
w , ,
o o o
r l l
l l l
d e e
!dlrow ,olleH H
d e e
l l l
r l l
o o o
w , ,
, w w
o o o
l r r
l l l
e dd
Hello, world!
Input:
Hi
Output:
Hi
iHH
Hi
Reference Implementation in Python
text = raw_input("Enter a string: ")
print " " * (len(text) - 1) + text
spaces = len(text) - 2
_spaces = spaces
for i in range(1, len(text) - 2 + 1):
print " " * spaces + text[i] + " " * _spaces + text[(i + 1) * -1] + " " * (_spaces - spaces) + text[(i + 1) * -1]
spaces -= 1
print text[::-1] + " " * _spaces + text[0]
spaces = _spaces - 1
for i in range(1, len(text) - 2 + 1):
print text[(i + 1) * -1] + " " * _spaces + text[i] + " " * spaces + text[i]
spaces -= 1
print text
Rules
- This is code-golf, so shortest answer in bytes wins! Tiebreaker is most upvoted.
- Standard loopholes are disallowed.
- Trailing newline and trailing spaces are allowed.
acrolith
- 4k
- 1
- 25
- 41