(no, not those ones)
The Challenge
You'll be given two inputs. The first is a positive integer n > 0
, which is used to output an n x n
right triangle of the numbers 1, 2, 3, ... n
. This triangle starts in a corner and increases horizontally and vertically by one and diagonally by two. See examples below for clarification. Keep one space between columns and keep all numbers right-aligned in their particular columns. (This is ascii-art after all).
The second input, x
, is one of four distinct single ASCII characters of your choice that determines the triangle's starting corner (and hence orientation). For example, you could use 1,2,3,4
or a,b,c,d
or #,*,!,)
, etc. Please specify in your answer how the orientation works.
For clarification in this challenge, I will use 1,2,3,4
which will correspond to 1
for the upper-left, 2
for the upper-right, and so on clockwise.
The Examples
For example, for n = 5
, x = 1
output the following:
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
For input n = 11
, x = 1
output the following (note the extra spaces so the single digits are right-aligned):
1 2 3 4 5 6 7 8 9 10 11
2 3 4 5 6 7 8 9 10 11
3 4 5 6 7 8 9 10 11
4 5 6 7 8 9 10 11
5 6 7 8 9 10 11
6 7 8 9 10 11
7 8 9 10 11
8 9 10 11
9 10 11
10 11
11
With input n=6
and x=2
output:
6 5 4 3 2 1
6 5 4 3 2
6 5 4 3
6 5 4
6 5
6
With input n = 3
and x = 4
, output:
3
2 3
1 2 3
With input n = 1
and any x
, output:
1
The Rules
- Leading/trailing newlines or other whitespace are optional, provided that the numbers line up appropriately. (For example, trailing whitespace to make a square output is acceptable).
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Output can be to the console, saved as an image, returned as a list of strings, etc. Any convenient and allowed format.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.