Find any possible two coordinates of Rectangle whose two coordinates are given | Function to find the remaining two rectangle coordinates ; Pairs to store the position of given two coordinates of the rectangle . ; Pairs to store the remaining two coordinates of the rectangle . ; Traverse through matrix and find pairs p1 and p2 ; First Case ; Second Case ; Third Case ; Print the matrix ; Driver code ; Given Input ; Function Call
def Create_Rectangle ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT arr [ i ] = [ i for i in arr [ i ] ] NEW_LINE DEDENT p1 = [ - 1 , - 1 ] NEW_LINE p2 = [ - 1 , - 1 ] NEW_LINE p3 = [ ] NEW_LINE p4 = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if ( arr [ i ] [ j ] == '1' ) : NEW_LINE INDENT if ( p1 [ 0 ] == - 1 ) : NEW_LINE INDENT p1 = [ i , j ] NEW_LINE DEDENT else : NEW_LINE INDENT p2 = [ i , j ] NEW_LINE DEDENT DEDENT DEDENT DEDENT p3 = p1 NEW_LINE p4 = p2 NEW_LINE if ( p1 [ 0 ] == p2 [ 0 ] ) : NEW_LINE INDENT p3 [ 0 ] = ( p1 [ 0 ] + 1 ) % n NEW_LINE p4 [ 0 ] = ( p2 [ 0 ] + 1 ) % n NEW_LINE DEDENT elif ( p1 [ 1 ] == p2 [ 1 ] ) : NEW_LINE INDENT p3 [ 1 ] = ( p1 [ 1 ] + 1 ) % n NEW_LINE p4 [ 1 ] = ( p2 [ 1 ] + 1 ) % n NEW_LINE DEDENT else : NEW_LINE INDENT p3 [ 0 ] , p4 [ 0 ] = p4 [ 0 ] , p3 [ 0 ] NEW_LINE DEDENT arr [ p3 [ 0 ] ] [ p3 [ 1 ] ] = '1' NEW_LINE arr [ p4 [ 0 ] ] [ p4 [ 1 ] ] = '1' NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( " " . join ( arr [ i ] ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE arr = [ "0010" , "0000" , "1000" , "0000" ] NEW_LINE Create_Rectangle ( arr , n ) NEW_LINE DEDENT