Find whether only two parallel lines contain all coordinates points or not | Find if slope is good with only two intercept ; if set of lines have only two distinct intercept ; Function to check if required solution exist ; check the result by processing the slope by starting three points ; Driver code
< ? php function isSlopeGood ( $ slope , $ arr , $ n ) { $ setOfLines = array_fill ( 0 , max ( $ arr ) * $ n , 0 ) ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ setOfLines [ $ arr [ $ i ] - $ slope * $ i ] = 1 ; $ setOfLines = array_unique ( $ setOfLines ) ; return ( count ( $ setOfLines ) == 2 ) ; } function checkForParallel ( $ arr , $ n ) { $ slope1 = isSlopeGood ( $ arr [ 1 ] - $ arr [ 0 ] , $ arr , $ n ) ; $ slope2 = isSlopeGood ( $ arr [ 2 ] - $ arr [ 1 ] , $ arr , $ n ) ; $ slope3 = isSlopeGood ( ( int ) ( ( $ arr [ 2 ] - $ arr [ 0 ] ) / 2 ) , $ arr , $ n ) ; return ( $ slope1 $ slope2 $ slope3 ) ; } $ arr = array ( 1 , 6 , 3 , 8 , 5 ) ; $ n = count ( $ arr ) ; echo ( int ) checkForParallel ( $ arr , $ n ) . " " ; ? >