There are 4 regular polygons that we can construct using ASCII art:
. . .
. . . . . . .
. . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
. . . . . . .
. . .
That is, a triangle, a square, a hexagon and an octagon.
Your task is to take two inputs and produce the corresponding ASCII art polygon.
Input
The two inputs will be:
- A string/list of printable ASCII characters (i.e. with code points in the range \33ドル\$ (
!) to \126ドル\$ (~)
- An indicator as to which polygon you should output. This indicator can be any \4ドル\$ distinct and consistent values (e.g.
1234, ABCD, etc.), but each must be only one character long, to avoid any exploitation of this input.
The string will be a perfect fit for the polygon, meaning that, if the shape to be outputted is:
The string may have repeated characters, but will always fit the appropriate lengths for the given shape/sequence, so there is no need to worry about too many/few characters.
Output
You should output a shape, indicated by the second input, in the format shown at the top of the challenge with the . replaced with the characters in the inputted string. Each character must be separated by a single space, and leading/trailing whitespace is acceptable, so long as the shape is preserved. The characters may be used in any order, but each character in the string must only appear once. For example, for a hexagon using ABCDABC, the following are valid:
A B B A
C D A A B C
B C D C
as each character from the string is used once. However,
A A A B AD
A A A A B C ABC
A A C A BC
are not valid (the first only has A, the second doesn't have a D and the third doesn't have spaces between characters).
This is code-golf so the shortest code in bytes wins
Test cases
These test cases use T, S, H and O to indicate which shape the output should be in. The string of characters is on the first line and the indicator on the second
i1+K8{^wsW
O
i 1
+ K 8
{ ^ w
s W
,r1~vi4l{W@+r<vzP;mq>:8gJcgg$j`$RFhDV
H
, r 1 ~
v i 4 l {
W @ + r < v
z P ; m q > :
8 g J c g g
$ j ` $ R
F h D V
0J++
S
0 J
+ +
Kn[Vyj
T
K
n [
V y j
#5~m
S
# 5
~ m
'*g(AUFV~Ou2n=172s'|S11q&j=+#
O
' * g
( A U F
V ~ O u 2
n = 1 7 2
s ' | S 1
1 q & j
= + #
f=for -2 bytes: Try it online! \$\endgroup\$