-1
\$\begingroup\$

Objective

To flip the rows and columns of a table in a challenge.

Instructions

You will be passed a "table" of 3 arrays/lists with 3 items each as input. Your job is to flip the rows and columns on it by writing a program that can do this efficiently and creatively. You will flip the "table" according to the example below.

Example

Input

["foo", 5, 0b1011]
[3.14, "bar", 10]
["apple", 90, "monty"]

Output

["foo", 3.14, "apple"]
[5, "bar", 90]
[0b1011, 10, "monty"]

Qualification

In order to qualify for winning, you must:

  1. Solve the challenge (use the above input for a test case)
  2. Optional: Post a link to an ideone or repl.it
  3. Follow standard loopholes
  4. Put a header in the format: Language, XX bytes.

This is , so least bytes wins. Good Luck!

Leaderboard

var QUESTION_ID=127611,OVERRIDE_USER=46066;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
  • 3
    \$\begingroup\$ Is STDIN required? Can we not use the Standard IO? \$\endgroup\$ – ATaco Jun 21 '17 at 0:50
  • 2
    \$\begingroup\$ Please edit the question to remove the IO restrictions. \$\endgroup\$ – CalculatorFeline Jun 21 '17 at 1:00
  • 1
    \$\begingroup\$ This challenge's IO seems to be geared towards a particular language (Not sure which one), and is unusually restrictive about it when handling IO doesn't seem like it should be the main focus of the challenge. I strongly recommend allowing much more flexible IO. \$\endgroup\$ – ATaco Jun 21 '17 at 1:06
  • 3
    \$\begingroup\$ In the future, I recommend using the Sandbox to get early feedback on your question. \$\endgroup\$ – ATaco Jun 21 '17 at 1:16
  • 1
    \$\begingroup\$ Voting to reopen as this is on the diagonal, not the antidiagonal. \$\endgroup\$ – CalculatorFeline Jun 21 '17 at 2:01
2
\$\begingroup\$

Mathematica, 3 bytes

This character (U+F3C7) is Mathematica's builtin Transpose suffix operator.

\$\endgroup\$
  • \$\begingroup\$ Yes it is accepted. \$\endgroup\$ – juniorRubyist Jun 21 '17 at 1:12
2
\$\begingroup\$

Math.JS, 1 byte

'

' is a named operator which takes it's left argument and transposes it.

Try it out

\$\endgroup\$
  • \$\begingroup\$ Doesn't output in the correct format. \$\endgroup\$ – juniorRubyist Jun 21 '17 at 0:58
  • \$\begingroup\$ @juniorRubyist That's fine. But do consider that it does technically solve the challenge. \$\endgroup\$ – ATaco Jun 21 '17 at 1:00
1
\$\begingroup\$

Pyth, 1 byte

C

Pyth's C command transposes the given nested list.

\$\endgroup\$
1
\$\begingroup\$

TI-Basic, 2 bytes

AnsT

Not eligible for "winning" due to specification #2 but a valid answer nonetheless.

\$\endgroup\$
  • \$\begingroup\$ Please use a code block. \$\endgroup\$ – CalculatorFeline Jun 21 '17 at 1:23
  • \$\begingroup\$ @CalculatorFeline: The answer appears to be using HTML to reproduce characters that are in TI-Basic's character set but not in ASCII. You could use Unicode instead, though: Ansᵀ. \$\endgroup\$ – user62131 Jun 21 '17 at 1:25
1
\$\begingroup\$

Jelly, 1 byte

Z

Try it online!

Footer added on the TIO link to make the result easier to see.

This is Jelly's builtin for Zip.

\$\endgroup\$
1
\$\begingroup\$

Python, 3 bytes

zip

Note that you must pass the arguments not in a list, but rather as separate arguments, which I believe is acceptable. If not, lambda x:zip(*x) works too for a list as a parameter.

If builtins are not allowed (which was not specified), lambda x:[[b[a]for b in x]for a in range(len(x[0]))] works, or, since it's specified to be 3 × 3, lambda x:[[b[a]for b in x]for a in[1,2,3]] works.

If you're going to enforce the strict IO, then here you go:

print(zip(*[input()for i in'3cs'])) # '3cs' because why not, CalcCat
\$\endgroup\$
  • \$\begingroup\$ @juniorRubyist Functional under site standards. Override standards and enforce STDIN? (not recommended) \$\endgroup\$ – HyperNeutrino Jun 21 '17 at 1:03
  • \$\begingroup\$ [0]*3 can be "3cs" for +customizability. \$\endgroup\$ – CalculatorFeline Jun 21 '17 at 1:40
  • \$\begingroup\$ @CalculatorFeline Oh smart. Thanks! \$\endgroup\$ – HyperNeutrino Jun 21 '17 at 1:44
  • \$\begingroup\$ wait that doesn't save bytes. nvm. but still, nice \$\endgroup\$ – HyperNeutrino Jun 21 '17 at 1:45
1
\$\begingroup\$

Python 2, 44 51 bytes

Crossed out 44 is still 44 :(

for i in zip(*[input()for i in"hi!"]):print list(i)

Try it online!

Follows original IO rules. Only works for 3 high input (other heights are not required). Change the length of "hi!" to height of input.

\$\endgroup\$
  • \$\begingroup\$ You can't request for the code to be changed given the input. You need to account for it somehow programmatically. \$\endgroup\$ – NoOneIsHere Jun 21 '17 at 1:43
  • \$\begingroup\$ Nope. See question. \$\endgroup\$ – CalculatorFeline Jun 21 '17 at 1:46
  • \$\begingroup\$ Ok, sorry. I see that you only need to support up to three. You might want to mention, though, Only works for `3` high input, as required. \$\endgroup\$ – NoOneIsHere Jun 21 '17 at 1:48
1
\$\begingroup\$

MacOS bash, 6

rs -Tc

Works on Linux as well, if rs is installed, as TIO:

Try it online.

\$\endgroup\$
0
\$\begingroup\$

Haskell, 26 bytes

import Data.List
transpose

This is a built-in

\$\endgroup\$

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