-2
\$\begingroup\$

The task is simple, given an integer n of how many lines the next n lines is and, a multi-line input, output the resulting 90 degree tilted grid in a clockwise formation.

E.g.

Input:

2
c d
o e

Output:

o c
e d

I/O format:

  1. Input will have spaces in between them
  2. Input always contains alphabetical characters except the first input n

This is code-golf, so shortest code wins!

Credit: https://www.codingame.com/contribute/view/727778c431888fc6c0d03c77037ad93c3fa4 by Tsloa

\$\endgroup\$
13
  • 11
    \$\begingroup\$ This is also not very clear. What do you mean by "a so-called grid"? Will it always be a multi-line string of letters? Will it always have spaces between the cells? This is why we strongly recommend you post your challenges in the sandbox: to sort out these problems before you post them on the main site. A lot of your past challenges have been poorly received, so please use the sandbox in future. \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 9:34
  • 4
    \$\begingroup\$ Leave your post in the sandbox for several days, and then you will be more likely to get any feedback. If you get no comments, and just some upvotes, it's probably a good challenge; if you get none whatsoever, you can also ask for feedback explicitly in our chatroom \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 9:39
  • 1
    \$\begingroup\$ Since multi-line strings may be treated as lists of one-line strings, and since strings are basically lists of characters, this is essentially the same as a 2D array. I disagree that this should be closed as a duplicate of that one, though, because that one is already closed, and there isn't really a point in that. \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 9:43
  • 1
    \$\begingroup\$ Is this challenge from another site? \$\endgroup\$
    – xnor
    Jan 17, 2022 at 9:46
  • 2
    \$\begingroup\$ That seems to be based on a clash from codingame. I'm not sure about the licensing of those, but you should definitely credit the original author \$\endgroup\$
    – ovs
    Jan 17, 2022 at 10:02

5 Answers 5

2
\$\begingroup\$

Japt -R, 7 bytes

z would work on its own if the spacing between characters and lines were consistent.

·m¸z m¸

Try it

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

Charcoal, 8 bytes

FN↓⟦⟦⁻S `

Try it online! Link is to verbose version of code. Explanation:

FN

Input the number of lines and loop that many times:

↓⟦⟦⁻S `

Remove spaces from the next line of input, then output it vertically and move the cursor two spaces leftwards.

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

05AB1E (legacy), 6 (or 7?) bytes

|€#øí»

Try it online.

It doesn't need the length as input, but if it's mandatory for whatever reason, you can add a ¦ after the | to simply remove it from the list of inputs:
Try it online.

Could be 2 bytes with standard I/O:
Try it online.

Explanation (of the 7 bytes program):

|        # Get all lines of input as a list
 ¦       # Remove the first item (the additional length)
  €#     # Split each line on spaces
    øí   # Rotate the matrix 90 degrees clockwise:
    ø    #  Zip/transpose; swapping rows/columns
     í   #  Reverse each inner row
      »  # Join each inner list by spaces, and then these strings by newlines
         # (after which the result is output implicitly)
\$\endgroup\$
0
\$\begingroup\$

Python3, 60 bytes

_,*R=map(str.split,open(0))
for r in zip(*R[::-1]):print(*r)

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Why do you think it needs to be a one-liner? \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 9:33
  • \$\begingroup\$ hmm? i didnt say that im saying if i could i would but i cant (as a one liner u can use lambda) \$\endgroup\$
    – DialFrost
    Jan 17, 2022 at 9:33
  • 1
    \$\begingroup\$ You can just submit it as a full program: Try it online!. Except that your answer doesn't seem to work, because it always ignores the first line of input. You can change _,*R to *R, to fix this \$\endgroup\$
    – pxeger
    Jan 17, 2022 at 9:36
  • \$\begingroup\$ sry i changed the IO format of the qns \$\endgroup\$
    – DialFrost
    Jan 17, 2022 at 9:39
0
\$\begingroup\$

Pari/GP, 89 bytes

[[print1(c,if(j--," ","\n"))|c<-r]|r<-Mat(Colrev([Vec(Str(input))|i<-[1..n=input]])),j=n]

Try it online!

Pari/GP 2.13.0, 71 bytes

[print(strjoin(r," "))|r<-Mat(Colrev([Vec(Str(input))|i<-[1..input]]))]

The newest version of PARI/GP finally has a strjoin function. But no TIO.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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