Construct a Matrix with no element exceeding X and sum of two adjacent elements not exceeding Y | Function to print the required matrix ; For 1 * 1 matrix ; Greater number ; Smaller number ; Sets / Resets for alternate filling of the matrix ; Print the matrix ; If end of row is reached ; Driver Code
def FindMatrix ( n , m , x , y ) : NEW_LINE INDENT if ( n * m == 1 ) : NEW_LINE INDENT if ( x > y ) : NEW_LINE INDENT print ( y ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( x ) NEW_LINE DEDENT return NEW_LINE DEDENT a = min ( x , y ) NEW_LINE b = min ( 2 * x , y ) - a NEW_LINE flag = True NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if ( flag ) : NEW_LINE INDENT print ( a , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( b , end = " ▁ " ) NEW_LINE DEDENT flag = not flag NEW_LINE DEDENT if ( ( ( n % 2 != 0 and m % 2 == 0 ) or ( n % 2 == 0 and m % 2 == 0 ) ) ) : NEW_LINE INDENT flag = not flag NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT N = 3 NEW_LINE M = 3 NEW_LINE X = 5 NEW_LINE Y = 3 NEW_LINE FindMatrix ( N , M , X , Y ) NEW_LINE