«¾6ÅÈΛ
Input as a pair of integers, where the first is the height and the second is the width.
Outputs with 0
as characters.
Try it online.
Explanation:
Λ # Use the Canvas builtin with the following three options:
# (after which the resulting shape is output implicitly immediately afterwards)
« # - line lengths: use the (implicit) input-integer, merged with itself: [h,w,h,w]
6ÅÈ # - the directions: push a list of even integers <= 6: [0,2,4,6]
¾ # - what to draw: push the counter variable, which is 0 by default
The Canvas builtin uses three arguments to draw a shape:
- Character/string to draw: character
0
, which could alternatively be 1
/2
by replacing the ¾
with X
/Y
respectively.
- Length of the lines we'll draw: the input-list twice. Since there is more than one input-length, these are leading for the Canvas builtin, so we'll need the additional merge
«
at the start, otherwise it would only draw the top and left borders, instead of the entire box.
- The direction to draw in:
[0,2,4,6]
. The digits in the range \$[0,7]\$ each represent a certain direction:
7 0 1
↖ ↑ ↗
6 ← X → 2
↙ ↓ ↘
5 4 3
So the [0,2,4,6]
in this case translate to the directions \$[↑,→,↓,←]\$.
Here a step-by-step explanation of the output (we'll use input-lengths [3,5]
as example here):
Step 1: Draw 3 0
characters in direction 0↑
:
0
0
0
Step 2: Draw 5-1 0
characters in direction 2→
:
00000
0
0
Step 3: Draw 3-1 0
characters in direction 4↓
:
00000
0 0
0 0
Step 4: Draw 5-1 0
characters in direction 6←
:
00000
0 0
00000
See this 05AB1E tip of mine for an in-depth explanation of the Canvas builtin.