Trapezium Order
you are given an integer N . print N rows starting from 1 in the trapexium order as shown in the output of the below examples .
Input
the input contains an integer N
OUTPUT
the output should have N lines
each of the N lines should have space -seperated integers as per the trapezium order
SAMPLE INPUT 1
4
SAMPLE OUTPUT 1
1 2 3 4 17 18 19 20
5 6 7 14 15 16
8 9 12 13
10 11
n = int(input())
k = 1
res = []
for i in range(n):
res.append(" ".join([str(j) for j in range(k, k+n-i)]))
k += n-i
for i in range(n):
res[-1-i] += " " + " ".join([str(j) for j in range(k, k+1 + i)])
k += 1 + i
print(*res, sep="\n")
Comments
Leave a comment