Tuesday, September 26, 2017

Pattern Printing - Diamond Numbers

Given an integer N as the input, print the pattern as given in the Example Input/Output section.

Input Format:
The first line contains N.

Output Format:
2N-1 lines containing the desired pattern.

Boundary Conditions: 2 <= N <= 50

Example Input/Output:
Input:
3
Output:
0 0 1 0 0
0 2 0 8 0
3 0 0 0 7
0 4 0 6 0
0 0 5 0 0

Solution:
n = int(input())
for i in range(1,2*n):
    for j in range(2*n-1):
        if j==n-i or j==i-n:
            print(i,end=' ')
        elif j==n+i-2 or j==3*n-i-2:
            print(4*n-2-i,end=' ')
        else:
            print("0",end=' ')
    print()
Share: