| Bytes | Lang | Time | Link |
|---|---|---|---|
| 045 | Nibbles | 250826T221719Z | Adam |
| 003 | Pip | 250825T192758Z | DLosc |
| 067 | AWK | 250825T184606Z | xrs |
| 009 | Uiua | 231113T192615Z | chunes |
| 036 | Perl 5 lp Mfeature=say | 190331T202053Z | Pavel |
| 029 | Proton | 190402T163123Z | hyperneu |
| 030 | Add++ | 180305T171556Z | caird co |
| 088 | awk | 180308T153410Z | mmuntag |
| 056 | Clojure | 180308T141148Z | Joshua |
| 049 | Python 3 | 180307T011929Z | Dat |
| 005 | Charcoal | 180305T184052Z | Erik the |
| 111 | C gcc | 180306T001341Z | Jonathan |
| nan | SNOBOL4 CSNOBOL4 | 180305T171119Z | Giuseppe |
| 012 | V | 180305T162847Z | DJMcMayh |
| 011 | J | 180306T103622Z | Adá |
| 049 | Julia 0.6 | 180306T061811Z | Frames C |
| 131 | Java 8 | 180306T081650Z | Kevin Cr |
| 012 | J | 180306T083521Z | Galen Iv |
| 046 | JavaScript Node.js | 180306T035458Z | Shieru A |
| 002 | 05AB1E | 180305T162334Z | Magic Oc |
| 035 | Ruby | 180305T224653Z | benj2240 |
| 007 | APL Dyalog Classic | 180305T212148Z | ngn |
| 029 | Octave | 180305T204615Z | Steadybo |
| 002 | SOGL V0.12 | 180305T202011Z | totallyh |
| 001 | Canvas | 180305T204520Z | dzaima |
| 029 | Mathematica | 180305T185554Z | totallyh |
| 013 | Retina | 180305T163411Z | Martin E |
| 006 | Japt | 180305T174122Z | Shaggy |
| 005 | Stax | 180305T170211Z | recursiv |
| 005 | MATL | 180305T170103Z | Giuseppe |
| 011 | APL+WIN | 180305T164641Z | Graham |
| 024 | Haskell | 180305T162454Z | nimi |
| 057 | R | 180305T164007Z | Giuseppe |
| 006 | Husk | 180305T161949Z | Mr. Xcod |
| 031 | Triangularity | 180305T161111Z | Mr. Xcod |
| 038 | Python 3 | 180305T160732Z | pizzapan |
| 005 | Jelly | 180305T160257Z | Erik the |
Nibbles, 4.5 bytes
;!$.@\$:\
;!$.@\$:\
! : Join each row
$ of the input
@ with the input
. \$ with each row reversed
; Save the result
\ and join it with the reverse of itself
Pip, 3 bytes
There is a builtin operator, QuadReflect:
QR_
The code is an anonymous function that takes and returns a nested list. Attempt This Online!
Without using QuadReflect or its relative Reflect (RF), a function would be 15 bytes:
{_AL R_MaAL Ra}
{_AL R_MaAL Ra}
{ } Anonymous function of argument a:
aAL To a, append the list...
Ra Reverse(a)
M To each row, map this function:
_AL R_ To the argument, append its reverse
AWK, 67 bytes
{for(d=$0;NF;NF--)d=d FS$NF;$0=s[++i]=d}1;END{for(;i;)print s[i--]}
Very similar to previous AWK answer but independently found.
Uiua, 9 bytes
⍥(⍉⊂∶⇌.)2
⍥(⍉⊂∶⇌.)2
⍥( )2 # run a function twice
. # duplicate
⇌ # reverse
⊂∶ # prepend
⍉ # transpose
Perl 5 -lp -Mfeature=say, 36 bytes
unshift@l,$_.=reverse;END{say for@l}
Deparsed:
BEGIN { $/ = "\n"; $\ = "\n"; }
use feature 'say';
LINE: while (defined($_ = readline ARGV)) {
chomp $_;
unshift @l, $_ .= reverse;
sub END {
say $_ foreach (@l);
}
}
continue {
die "-p destination: $!\n" unless print $_;
}
Proton, 29 bytes
a=>[b+b[by-1]for b:a+a[by-1]]
There are a few other interesting approaches though:
Proton, 29 bytes
a=>map(g,(g=x=>x+x[by-1])(a))
You can define the mirror sub-function g in-line, because Proton. It's not shorter though.
Proton, 36 bytes
(a=>[x[0]for x:zip(*(a+a[by-1]))])*2
This should be (a=>zip(*(a+a[by-1])))*2 which is 24 bytes, but the zip function is completely broken. Basically, you mirror it and zip, and then do that twice (you can multiply a function by a positive integer to apply the function multiple times).
Add++, 30 bytes
D,f,@,bU€{r}B]{r}
D,r,@,dbR+
The footer simply transforms the nested array into the format in the question. Defines a function f, which expects a matrix (nested array) as an argument.
awk, 88 bytes
{s="";for(i=NF;i>0;i--)s=" "$i s" "$i;a[FNR]=s;print s}END{for(i=NR;i>0;i--)print a[i]}
Clojure, 56 bytes
(fn[i](map #(concat %(reverse %))(concat i(reverse i))))
Creates an anonymous function which takes the two dimensional list and returns the fixed rectangle as two dimensional list.
Python 3, 49 bytes
def f(a):o=[i+i[::-1]for i in a];return o+o[::-1]
Where a is the input array. This function will return a 2D array.
C (gcc), 114 111 bytes
- Saved three bytes thanks to Kevin Cruijssen; inverting the loops.
j,i;f(A,w,h)int*A;{for(i=h+h;i-->0;puts(""))for(j=w+w;j-->0;)printf("%d,",A[(i<h?i:h+h+~i)*w+(j<w?j:w+w+~j)]);}
C (gcc), 109 bytes (abusing ease of parsing)
- Thanks to Kevin Cruijssen for suggesting to only allow one-digit input integers; saved two bytes.
j,i;f(A,w,h)int*A;{for(i=h+h;i-->0;puts(""))for(j=w+w;j-->0;)putchar(A[(i<h?i:h+h+~i)*w+(j<w?j:w+w+~j)]+48);}
SNOBOL4 (CSNOBOL4), 119 113 bytes
T =TABLE()
I X =X + 1
I =INPUT :F(D)
OUTPUT =T<X> =I REVERSE(I) :(I)
D X =X - 1
OUTPUT =GT(X) T<X> :S(D)
END
Takes input as strings on STDIN, without spaces. This only works because the digits are 1-9 and would fail otherwise.
V, 12 bytes
yGæGPÎy$æ_|P
Explanation:
yG " Yank every line
æG " Reverse the order of the lines
P " Paste what we yanked
Î " On every line:
y$ " Yank the whole line
æ_ " Reverse the whole line
| " Move to the beginning of the line
P " Paste what we yanked
J, 11 bytes
Anonymous tacit prefix function.
|:@(,|.)^:2
|: transpose
@(…) the result of:
, the argument followed by
|. its reverse
^:2 and all this done twice
Julia 0.6, 55 49 bytes
~i=i:-1:1
!x=[x x[:,~end];x[~end,:] x[~end,~end]]
~(i) is a function to create slice from i down to 1.
So ~end gives the slice end:-1:1
!(x) is the function to do the rebuilding of the array.
Java 8, 140 131 bytes
m->{String r="";for(int a=m.length,b=m[0].length,i=a+a,j;i-->0;r+="\n")for(j=b+b;j-->0;)r+=m[i<a?i:a+a+~i][j<b?j:b+b+~j];return r;}
Explanation:
m->{ // Method with integer-matrix parameter and String return-type
String r=""; // Result-String, starting empty
for(int a=m.length, // Amount of rows of the input-matrix
b=m[0].length, // Amount of columns of the input-matrix
i=a+a,j; // Index integers
i-->0; // Loop over double the rows
r+="\n") // After every iteration: append a new-line to the result
for(j=b+b;j-->0;) // Inner loop over double the columns
r+= // Append the result with:
m[i<a? // If `i` is smaller than the amount of rows
i // Use `i` as index in the input-matrix
: // Else:
a+a+~i] // Use `a+a+i-1` as index instead
[j<b? // If `j` is smaller than the amount of columns
j // Use `j` as index in the input-matrix
: // Else:
b+b+~j]; // Use `b+b+j-1` as index instead
return r;} // Return the result-String
J, 12 bytes
(,|.)@,.|."1
Explanation
|."1 - reverse each row
,. - and stitch them to the input
( )@ - and
,|. - append the rows in reversed order
JavaScript (Node.js), 62 55 49 46 bytes
A=>(j=x=>[...x,...[...x].reverse()])(A).map(j)
Because Array.prototype.reverse() reverses the array in place, I have to make a shallow copy somewhere first. A=>(j=x=>[...x,...x.reverse()])(A).map(j) does not work.
05AB1E, 2 bytes
∞∊
# Input:Array of String | ['12','34']
---#-----------------------+------------------------------------------
∞ # Mirror horizontally. | [12,34] -> [1221,3443]
∊ # Mirror vertically. | [1221,3443] -> [1221\n3443\n3443\n1221]
Credit for Mr. Xcoder pointing out that arrays of string may count as 2D arrays and Pavel for confirming it.
Ruby, 35 bytes
->a{r=->b{b+b.reverse}
r[a].map &r}
A lambda accepting a 2D array and returning a 2D array. It's straightforward, but here's the ungolfed version anyway:
->a{
r=->b{ b+b.reverse } # r is a lambda that returns the argument and its reverse
r[a].map &r # Add the array's reverse, then add each row's reverse
}
Retina, 13 bytes
\%`$
$^$`
Vs`
Explanation
\%`$
$^$`
On each line (%), match the end of the line ($), and insert the reverse ($^) of the entire line ($`) and print the result with a trailing linefeed (\). This does the reflection along the vertical axis and prints the first half of the output.
Vs`
This just reverses the entire string, which is equivalent to a 180° degree rotation, or in our case (due to the horizontal symmetry) a reflection along the horizontal axis. This way this works is that V's (reverse) default regex is (?m:^.*$), which normally matches each line of the string. However, we activate the singleline option s, which makes . match linefeeds as well and therefore this default regex actually matches the entire string.
The result of this is printed automatically at the end of the program, giving us the second half of the output.
Japt, 6 bytes
mê1 ê1
Explanation
:Implicit input of 2D array
m :Map
ê1 : Mirror sub array
ê1 :Mirror main array
Stax, 5 bytes
:mm:m
:m means mirror, which is input.concat(reverse(input)). m, in this context means output each line after applying...
So, mirror the array of rows, and then mirror each row and output.
MATL, 5 bytes
,tPv!
Explanation:
(implicit input)
, # do twice:
t # dup top of stack
P # flip vertically
v # vertically concatenate
! # transpose
(implicit output)
APL+WIN, 11 bytes
Prompts for a 2d array of integers.
m⍪⊖m←m,⌽m←⎕
Husk, 7 6 bytes
Coincidentally, Erik had posted the exact same code in the Husk chatroom about a minute before I posted this.
‼oTS+↔
Pervious version, 7 bytes:
mS+↔S+↔
Triangularity, 31 bytes
...)...
..IEM..
.DRs+}.
DRs+...
Explanation
Removing the characters that make up for the padding, here is what the program does:
)IEMDRs+}DRs+ – Full program. Takes a matrix as a 2D list from STDIN.
) – Push a 0 onto the stack.
I – Take the input at that index.
E – Evaluate it.
M } – For each row...
DR – Duplicate and replace the second copy by its reverse.
s+ – Swap and append.
DR – Duplicate the result and replace the second copy by its reverse.
s+ – Swap and append.
Python 3, 38 bytes
lambda a:[b+b[::-1]for b in a+a[::-1]]
Takes a list of lists and returns a list of lists.
Explanation:
lambda a: # anonymous lambda function
for b in a+a[::-1] # for each row in the array and the upside-down array
b+b[::-1] # the row with its reverse appended
[ ] # return in a list