Construct a Matrix N x N with first N ^ 2 natural numbers for an input N | Function to print the desired matrix ; Iterate ove all [ 0 , N ] ; If is even ; If row number is even print the row in forward order ; if row number is odd print the row in reversed order ; Given Matrix Size ; Function Call
def UniqueMatrix ( N ) : NEW_LINE INDENT element_value = 1 NEW_LINE i = 0 NEW_LINE while ( i < N ) : NEW_LINE INDENT if ( i % 2 == 0 ) : NEW_LINE INDENT for f in range ( element_value , element_value + N , 1 ) : NEW_LINE INDENT print ( f , end = ' ▁ ' ) NEW_LINE DEDENT element_value += N NEW_LINE DEDENT else : NEW_LINE INDENT for k in range ( element_value + N - 1 , element_value - 1 , - 1 ) : NEW_LINE INDENT print ( k , end = ' ▁ ' ) NEW_LINE DEDENT element_value += N NEW_LINE DEDENT print ( ) NEW_LINE i = i + 1 NEW_LINE DEDENT DEDENT N = 4 NEW_LINE UniqueMatrix ( N ) NEW_LINE