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*

Draw an ASCII Rectangle

Given two integers as input in an array, draw a rectangle, using the first integer as width and second as height.

Or, if your language supports it, the two integers can be given as separate inputs.

Assume the width and height will never be less than 3, and they will always be given.

Example Outputs:

[3, 3]

|-|
| |
|-|

[5, 8]

|---|
| |
| |
| |
| |
| |
| |
|---|

[10, 3]

|--------|
| |
|--------|

This is code-golf, so the answer with the lowest amount of bytes wins.

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ Passing a template function as a default argument? Clever! \$\endgroup\$ Commented Sep 19, 2016 at 1:04
  • \$\begingroup\$ If we allow nested functions (i.e. f(3)(5) instead of f(3,5)), one more byte can be saved \$\endgroup\$ Commented Jul 7 at 9:58

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