Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Create an ASCII line, given a length

Information

Create a diagonal line given its length (let’s call the variable, say, \$n\$ where \$n > 0\$)

  • The diagonal line starts from the top left and goes to the bottom right.
  • You must use the ASCII character \ for the line.
  • The input number can be given from STDIN or if your program doesn’t support that, use a hardcoded value in your code or pass it as an argument while running the program.
  • For padding, only use the space character 0x20
  • Trailing spaces and/or newlines are allowed.
  • The length of the line is the non whitespace characters

Here is an example program (59 bytes):

n = int(input())
for i in range(n):
 print(' ' * i + '\\')

Try it online!

Example:

Input: 4
Output
\
 \
 \
 \

Rules

  • Use standard I/O when possible.
  • Standard loopholes are forbidden.
  • This is code golf, so the shortest answer in bytes wins.
  • Please explain the code that you wrote.

Answer*

Draft saved
Draft discarded
Cancel
3
  • \$\begingroup\$ n o o o friggin ninjas \$\endgroup\$ Commented Jun 4, 2021 at 15:42
  • \$\begingroup\$ Alternative 6-byter using ú: ݨ'\ú»/L<'\ú». \$\endgroup\$ Commented Jul 29, 2021 at 9:48
  • \$\begingroup\$ @KevinCruijssen thanks, added the second suggestion. It would be really nice if j would automatically swap arguments for integer lists as well. \$\endgroup\$ Commented Jul 30, 2021 at 6:38

AltStyle によって変換されたページ (->オリジナル) /