Program to find all possible triangles having same Area and Perimeter | Function to print sides of all the triangles having same perimeter & area ; Stores unique sides of triangles ; i + j + k values cannot exceed 256 ; Find the value of 2 * s ; Find the value of 2 * ( s - a ) ; Find the value of 2 * ( s - b ) ; Find the value of 2 * ( s - c ) ; If triplets have same area and perimeter ; Store sides of triangle ; Sort the triplets ; Inserting in se to check avoid duplicate sides ; Print sides of all desired triangles ; Function call
const samePerimeterAndArea = ( ) => { let se = [ ] ; for ( let i = 1 ; i <= 256 ; ++ i ) { for ( let j = 1 ; j <= 256 ; ++ j ) { for ( let k = 1 ; k <= 256 ; ++ k ) { let peri = i + j + k ; let mul1 = - i + j + k ; let mul2 = i - j + k ; let mul3 = i + j - k ; if ( 16 * peri == mul1 * mul2 * mul3 ) { let v = [ i , j , k ] ; v . sort ( ( a , b ) => a - b ) ; let check = - 1 ; for ( let i = 0 ; i < se . length ; ++ i ) { if ( se [ i ] [ 0 ] == v [ 0 ] && se [ i ] [ 1 ] == v [ 1 ] && se [ i ] [ 2 ] == v [ 2 ] ) check = 1 ; } if ( check === - 1 ) se . push ( v ) ; } } } } for ( let it = 0 ; it < se . length ; ++ it ) { document . write ( ` ${ se [ it ] } ` ) ; } } samePerimeterAndArea ( ) ;