# I transpose the source code, you transpose the input!

Rip-off of a rip-off of a rip-off of a rip-off. Go upvote those!

Your task, if you wish to accept it, is to write a program/function that outputs/returns its input/argument¹. The tricky part is that if I transpose your source code², the output/result must be transposed too.

1. You may choose which kind of 2D data your solution can accept. For example a list of lists, a matrix, a list of strings, etc. State which one(s) it handles. You may assume that the input will always be rectangular and will have a length of 1 or more along each dimension.

2. For the purposes of transposing, short lines in your source code will be considered as padded with trailing spaces until it is rectangular, however, these padded trailing spaces do not contribute to your code length.

Since this is , the target is to optimize the byte count of the original source code (not the transposed version).

## Examples

Let's say your solution takes a numeric matrix and your source code is

AB
DEF


and its input/argument is [[1,2],[3,4],[5,6]]. If I write

AD
BE
F


instead and run it, the output/result must be [[1,3,5],[2,4,6]].

Let's say your solution takes a linefeed-separated string and your source code is

ABC


and its input/argument is "96\n". If I write

A
B
C


instead and run it, the output/result must be "9\n6\n".

• My god. Can we stop? – JL2210 Sep 22 at 16:30
• @Night2 No, it complicates matters. – Adám Sep 22 at 16:30
• @JL2210 No, I have a big one in the works. – Adám Sep 22 at 16:31
• These challenges are getting impossible in procedural languages without serious comment abuse. – JL2210 Sep 22 at 16:32
• @JL2210 Transforms. – Adám Sep 22 at 16:42

# Python 3 + numpy, 45 bytes

lambda\
a:a
ma= """
b.    "
dT"   "
a "
\ """


Try it online!

Thanks to @EriktheOutgolfer pointing out a bug of the previous version

## Transposed:

lambda\
a:a.T
ma= """
b     "
d "   "
a "
\ """


Try it online!

The functions take a numpy matrix as input and output a numpy matrix. The solution does not rely on comments like many other solutions do but instead exploits multi-line strings.

• That's really neat! – Adám Sep 22 at 19:43
• Hm, I'm pretty sure that the transposed version will be padded with spaces, so the last line will contain trailing spaces, therefore the \ will throw a SyntaxError. You need to move the quotes in both directions to fix this. – Erik the Outgolfer Sep 22 at 20:36
• @EriktheOutgolfer Fixed. Thanks. – Joel Sep 22 at 20:54

# Jelly, 2 bytes

Input is a list of lists. Thanks to Luis Mendo and Nick Kennedy for improving the answer.

ZZ


The program transposes the input twice, returning the original input. The transposed version ignores the first line and only transposes once.

# R, 5 4 bytes

#t
I


Try it online!

An R function, either the identity function I or the transpose function t when transposed. Footer on TIO shows output of both.

Thanks to @RobinRyder for saving a byte!

• You don't need the final #. – Robin Ryder Sep 22 at 18:58
• @RobinRyder thanks! For some reason I was padding to a rectangle even though I’d seen the statement that it was unnecessary. – Nick Kennedy Sep 22 at 18:59

# C (gcc), 209205203 201 bytes

## Normal

f(n,L,r,c)char**L;{for(c=0;0?L+  c:c<n;c+=puts(""))for(r=0;0?r :L[c][r];r++)putchar(L[ c ][ r ]);}/*
\\\      \\      1 [0][]      \ \\\  \   \\      1 <n          \  \\\\\\   r+-c c+-r    */


Try it online!

## Transposed

f
(
n
,
L
,
r
,
c
)
c\
h\
a\
r
*
*
L
;
{
f\
o\
r
(
c
=
0
;
01
?
L[
+0
]
[
c]
:
c
<
n
;
c
+\
=
p\
u\
t\
s
(
"\
"
)
)
f\
o\
r
(
r
=
0
;
01
?
r<
n
:
L
[
c
]
[
r
]
;
r
+\
+
)
p\
u\
t\
c\
h\
a\
r
(
L
[r
+
c-
c
]
[c
+
r-
r
]
)
;
}
/*
*/


Try it online!

This version is valid, but will not halt when given [] as input.

f
--(:[|,<zabf=]f
--abx(y-i$] -- ):x) pf;x[:x y =y  Try it online! ### Transposed, 75 bytes f--- ---y (a :b)= [x:y |(x ,y) <- zip a$f
b];
f x
= [
] :
f x


Try it online!

This version is valid, but crashes with [] as input for the transposed version.

f
--d[(idi)z[.]d!0
-- m!)|,<i0.$!] -- a! (_-p p=p  # Haskell, 7567 57 bytes At least 7 bytes saved thanks to Ørjan Johansen This version outputs [] when given [] as input. f --[[d(i<di)z[.$!0
a,
).
=.
>.
a$ra r) a/ y* _ m a p (*/  Try it online! ### Transposed (space padded): fn($a)=>array_map(
null,...$a)/* * ( /$
a
)
=
>
$a / */  Try it online! # Charcoal, 19 bytes Ａ¿⁰« ‖⁰¿ ↗⁰ ¿⁰ ⁰¿ «  Try it online! Takes input as an array of strings. Explanation: Ａ implicitly prints the explicit input, while ¿⁰ is a conditional, with 0 as the condition, which is therefore always false. « then starts a block of meaningless Charcoal code which never gets executed. (It might be possible to remove some of those bytes but in that case I'm not sure whether Charcoal would parse the program correctly.) Transposed, 17 bytes: Ａ‖↗¿⁰« ¿⁰⁰⁰¿ ⁰¿ «  Try it online! Explanation: Much the same as the previous program, except for the addition of the transpose command ‖↗. I have an alternative solution where both the original and transposed program are 18 bytes: Ａ⊞υ”y ‖υ⁺y ↗⁺ ⊞⁺ υ  Try it online! Explanation: Ａ as above; ⊞υ pushes a value to the predefined empty list (which doesn't affect the output); ”y begins an arbitrary string (ends at end of program or matching ”). Transposed: Ａ‖↗⊞υ ⊞υ⁺⁺ υ⁺ ”y y  Try it online! Explanation: Ａ‖↗ as above; ⊞υ as above; the minor difference here is that I'm pushing concatenations of smaller strings, since I don't want to repeat the ”. # Brain-Flak (BrainHack), 382375 337 bytes No comments!  ( <( <>)<> ><>) ({}) {}{} {( )()<({}<{}<><>>{}<><>{}) ( <>) ({}<><( [ ]({}<{}( )<({}()<{}<><>>){} ><><{}<< ><> ( [ ]( <>)<>)>{}<>>>)){}>)> ( ){ {}[]} <>[]{ (({}({} ( )) <>( ))[( [ ])])({}[ ] [ ]( ) ( ) < ><>{} <>( ){{}()<( )( ({} { [ ]( ) } <>) ( (()) {{}()<{} >} ) ) >} )}[] {} ( ){} ( ){}({}<>)<>([])}<>  Try it online! For the input the first two numbers are the dimensions of the matrix and the remainder is the contents of the matrix. Output is given in the same format. ## Transposed # Brain-Flak (BrainHack), 465 bytes  ( ( ({ } <( ({ } < > )( < >) ) > < > )< > (( { }) )) [ ( { }[ { }] ) ] ) {( ({ } )[ ( )] < ([ { }] <( { } < >) < > >( { } < >) < >< { }> )< > ({ } < > )< > (( { } < >) <{ ({ } [( ) ]< (( { }) <( { }( ({ } ) <{ ( { }[ ( )] <( { } < >) < > > )} { }< > >) < > <( { } <( <( ) >) < > { ({ } [( ) ]< ({ } < > ) < >> )} > { }) < > >) > )> )} { } > ) >) } ([ ] ) {{ } { }( [ ]) }{ } < >( [ ]) {{ } ( { } < > ) < > ( [ ] ) } < >  Try it online! # Japt, 2 bytes ÕU  ÕU :Implicit input of string/array U Õ :Transpose U U :Original U :Implicit output  Õ\nU :Implicit input of string/array U Õ :Transpose U \n :Reassign to U U :Newly transposed U :Implicit output  # JavaScript (Node.js), 62 bytes //m0()m ] //=](=a ) //>.a>p( ) //mm,m/aa //[ap./=[ p =>p  Try it online! Improved with a different layout ///// ///// m=>m[ 0].map ((a,p )=>m. map//= (a=> a[p ]))  # Haskell, 153 144 bytes (thanks, Sriotchilism O'Zaic) f [ ]= [ ]; f( x: l) =( :) x l -- : z$
-- f   i f
-- [   p
-- ]   W
--     i
--     t
--     h


Try it online!

Try it transposed!

• Here is a 144 byte version while maintaining your structure. (Transposed). – Wheat Wizard Sep 25 at 3:44
• Here is a 70 byte version that is still similar but with some structural changes. (Transposed). – Wheat Wizard Sep 25 at 4:08
• Thanks. The second version lacks the central idea though (re-using the foldr recursion for both versions), don't like that. – ceased to turn counterclockwis Sep 25 at 7:01
• You know, this challenge and your username kinda contradict each other, since your code did turn counterclockwise in that transposed version. ;p – Kevin Cruijssen Sep 25 at 7:50

# APL (Dyalog Unicode), 7 bytes

{⍵
⍉
⍵}


Try it online!

Transposed:

{⍉⍵
⍵ }


Probably a rather boring answer, but anyway here it goes.

The inline function definition {...} can span multiple lines. In this case, each line is sequentially executed, but any line without an assignment ← immediately returns its computed value. So the first function returns ⍵ while the second returns ⍉⍵.

Even more boring answer would be the comment abuse:

# APL (Dyalog Unicode), 4 bytes

⍝⍉
⊢


No TIO is necessary, I guess...

# 05AB1E, 3 bytes

øø
q


Try it online.

øq
ø


Try it transposed.

Explanation:

Unlike some of the other languages, newlines are simply ignored in 05AB1E, so I don't think a 2-byter is possible (although I'd love to be proven wrong).

ø    # Transpose the (implicit) input
ø   # Transpose it back
q  # Stop the program (and output the top of the stack implicitly as result)

ø    # Transpose the (implicit) input
q   # Stop the program (and output the top of the stack implicitly as result)
ø  # No-op, since the program has already stopped


# Ruby, 35 bytes

#-sz##
->hip{
hip  }
#{f
#ht*
#..h


Try it online!

Hip to be square! (Almost)

Accepts ruby matrices as input (arrays of arrays)

# Clean, 64 bytes

//i$//mp$ p=p
//ot
//rr
//ta
// n
//Ss
//tp
//do
//Ls
//ie
//b


Try it online!

//$////////// // ////////// import StdLib$p=transpose
p


Try it transposed!

# Python 3, 118 95 bytes

Input and result are lists of tuples.

f=lambda i:i;"""
=              "
l              "
a
m
b
d
a

i
:
[
*
z
i
p
(
*
i
)
]
;
"
"
"""


Try it online!

# Wolfram Language (Mathematica), 13 bytes

#&(*
 *)
\


# Cjam, 13 bytes

qo
~
z



Try it online!

## Transposed version:

q~z
o


Try it online!

## Input format

The input format is the standard CJam array format: [[1 2] [3 4]]

# No crash version, 12 bytes

The normal version crashes after printing the array. A version which doesn't crash would be:

qo{
~
z
 };


Try it online!

or transposed:

q~z
o
{  };


Try it online!

There are probably a few extra bytes that can be saved, i accidentaly worked on the transposed version first, which led to a few extra linebreaks and it's been a long time since i last used CJam. Any improvements welcome.

# Zsh, 75 bytes

  <<<${(F)@} fa< o[< r+$
+{
si(
;]F
i+)
==a
&$} &s r[ ei p+ e1 a] t$
#
s


TIO: Normal Transposed

The garbage below the main print is harmless, it prints an error when encountering a newline after fa< and exits. 86 bytes to remove that error.

The transposed version is here. After printing it errors on seeing < at the end of a line and exits.

 for s;i=&&repeat $#s a[++i]+=$s[i+1]
<<<${(F)a} < <$
{
(
F
)
@
}



# Runic Enchantments, 88 bytes

vrlril1-{)?\:',=4*?~r0[
i! '${U [0r/?*7̸0l{$
$ka6 ̹\!$,'/;? =  ̹
'              ̸

$ Input is space separated for each value and comma separated for each row (newlines are optional) and supports both strings and (non-zero) numbers. This makes parsing the input easier as input is automatically broken by spaces and newlines. So for example, the input: 1 2 3 , 4 5 6 , 7 8 9  Would be represented in nested array form as [[1,2,3],[4,5,6],[7,8,9]]. Minimal support for jagged arrays (only the last one can be short), but as inputs are expected to be rectangular, this satisfies that requirement. Output is represented in the same format (transposed version outputs with newlines, but its zero bytes different to use a space instead). Normal version has a trailing space, transposed version has a trailing comma and newline (due to the difficulty of determining when there is no more data to print). Normal version does have modifier characters in weird places (eg. 7̸0), but this is due to needing them in the right place when the source is transposed and the normal execution only utilizes the leftmost column of instructions. ### Explanation Explanation of the transposed source will be in a non-transposed form. Arrows will represent IP directionality at the entrance and exit of various blocks. →rlril1-{)?\:',≠4*?~r0[ Initial position. Read and parse input. ↓ Input loop exit and direction  The input is read, and when a , character is found, a new substack is pushed. This allows each stack to hold each row separately in memory. Enters next section from the top.  ↓ .. '${̹L [0r/?*7≠0l{̹$When no more input: ↑ ↓  [0 (executed leftwards) sets up a an empty stack to act as a boundary between the first row and the last row and then rotates to the first stack ({̹) and starts printing elements and rotating stacks. The i! is not executed and {̹L [0r is only executed once. When a zero-size stack is found, the loop exits.  ↑ ↓$ka6  \!$,'/;? Row separation formatting  When the empty-stack is found, a , and newline are printed, and value loop is re-entered. Execution order (mirrored for readability) where . is an un-executed command: \',$!.6ak\$?....../. Changing ak to '<space> would print spaces instead of newlines.

Execution halts when the program attempts to write from an empty stack; this is why only last-row jagginess works correctly and why there is a trailing , in the output: the comma has already been printed before the program knows that there's no more data.