8
\$\begingroup\$

In this challenge, your task is to input a rectangle ASCII pattern (You may assume only printable characters need to be handled, and you may assume a trailing newline or not), C4_4 symmetrify, and output it.

Here, C4_4 symmetric means symmetric under 90-degree rotation around a corner of the corner character. The corresponding "symmetrify" process is copy and rotate 90-degree clockwise three times, and then put all four copies together. For the precise arrangement, you can look at Test Cases.

Test Cases

Input:
asdf
jkl;

Output:
    ja
    ks
asdfld
jkl;;f
  f;;lkj
  dlfdsa
  sk
  aj


Input:
.O.
..O
OOO

Output:
.O.O..
..OO.O
OOOOO.
.OOOOO
O.OO..
..O.O.


Input:
gc
oo
ld
fe

Output:
  gc    
  oo    
  ldflog
  feedoc
codeef  
golfdl  
    oo  
    cg  

\$\endgroup\$
2
  • 6
    \$\begingroup\$ I'd suggest to add a test case where the height of the input is strictly greater than its width. \$\endgroup\$
    – Arnauld
    Oct 4, 2019 at 13:12
  • \$\begingroup\$ Hmm... emoticons? 4_4 \$\endgroup\$
    – S.S. Anne
    Oct 5, 2019 at 14:51

8 Answers 8

7
\$\begingroup\$

Charcoal, 6 bytes

A⟲C²⁴⁶

Try it online! Link is to verbose version of code. Explanation: implicitly prints the input, performs the rotation, signifies to keep copies, and ²⁴⁶ represents the numbers of 45-degree rotations to make. (Charcoal defaults to rotating around the bottom-right corner as desired.)

\$\endgroup\$
1
  • \$\begingroup\$ Yet another fastest gun! Yeah, Charcoal is very suitable for this challenge. Have a +1! \$\endgroup\$ Oct 4, 2019 at 12:39
4
\$\begingroup\$

Python 3, 193 bytes

def f(s):q=len(s[0])-len(s);s=[[" "]*len(s[0])]*q+s;s=[[" "]*-q+l for l in s];j=lambda a,b:[x+y for x,y in zip(a,b)];r=lambda x:[*map(list,zip(*x[::-1]))];return j(s,r(s))+j(r(r(r(s))),r(r(s)))

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I was not expecting this to happen. Nice work! \$\endgroup\$ Oct 4, 2019 at 13:06
3
\$\begingroup\$

J, 38 bytes

(,|."1@|.)@(,.|:@|.)@((2$_1*>./)@${.])

Try it online!

No doubt it can be golfed much further.

\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6),  178  173 bytes

Takes input as an array of strings. Returns a string.

m=>(g=x=>~y?(Y=y<w?y:W-y,X=x<w?x:W-x,Z=y<w^x<w?Y:X,(m[Z-z*d]||0)[(X^Y^Z)+!z*d]||' ')+[`
`[x-W]]+g(x<W?x+1:!y--):'')(0,w=m[0].length,h=m.length,d=w-h,(z=d>0)?0:w=h,y=W=w*2-1)

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Red, 217 bytes

func[a][n: max(l: length? a)length? a/1
p: copy""insert/dup p" "n
loop n - l[insert a copy p]forall a[pad/left a/1 n]repeat y n[repeat x n[append
a/:y a/(n - x + 1)/:y]]repeat y n[append a reverse copy a/(n - y + 1)]]

Try it online!

Returns a list of strings

\$\endgroup\$
9
  • 1
    \$\begingroup\$ pad, append, reverse! This is plain English. I like it. \$\endgroup\$ Oct 5, 2019 at 11:37
  • \$\begingroup\$ @TwilightSparkle Thanks! I like it too :) \$\endgroup\$ Oct 5, 2019 at 11:51
  • \$\begingroup\$ I'm curious why Red uses [] unlike lisp. \$\endgroup\$ Oct 5, 2019 at 12:01
  • \$\begingroup\$ @TwilightSparkle I don't know.. [] is a block (list), () is used for grouping \$\endgroup\$ Oct 5, 2019 at 12:04
  • 1
    \$\begingroup\$ Thanks for your explanation. I think I will probably get deeper into this language, maybe. \$\endgroup\$ Oct 6, 2019 at 1:37
1
\$\begingroup\$

Icon, 255 206 bytes

procedure f(a)
n:=*a;n<:=t:=*a[1]
1to n-*a&push(a,repl(" ",t))&\z
(!a)[1:1]:=repl(" ",n-t)&\z
i:=1to n&j:=1to n&a[i]||:=a[n-j+1,i]&\z
i:=1to n&put(a,"")&j:=1to 2*n&a[n+i]||:=a[n-i+1,2*n-j+1]&\z
return a
end

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ No Red answer? :P \$\endgroup\$ Oct 5, 2019 at 9:56
  • \$\begingroup\$ @TwilightSparkle Maybe I'll write one :) \$\endgroup\$ Oct 5, 2019 at 11:06
  • \$\begingroup\$ I'm waiting for it then LOL \$\endgroup\$ Oct 5, 2019 at 11:07
1
\$\begingroup\$

Python 3, 140 bytes

def f(a):l=len(a[0]);k=len(a)-l;b=[k*' '+i for i in-k*[l*' ']+a];b+=[*map(''.join,zip(*b))][::-1];return[i+j[::-1]for i,j in zip(b,b[::-1])]

Try it online!

Expects and returns a list of lines.

Explanation

def f(a):
 l=len(a[0]);k=len(a)-l;                     # Extract dimensions
 b=[k*' '+i for i in-k*[l*' ']+a];           # Make it square
 b+=[*map(''.join,zip(*b))][::-1];           # Construct left half of the output
 return[i+j[::-1]for i,j in zip(b,b[::-1])]  # Construct the right half and return
\$\endgroup\$
1
  • \$\begingroup\$ A nice approach! \$\endgroup\$ Oct 10, 2019 at 10:16
0
\$\begingroup\$

APL (Dyalog Unicode), 22 bytes

{(⌽⍪⊖)(⍉,⌽)⍵↑⍨-2/⌈/⍴⍵}

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.