Maximum count of Equilateral Triangles that can be formed within given Equilateral Triangle | Function to find the number of equilateral triangle formed within another triangle ; Check for the valid condition ; Number of triangles having upward peak ; Number of inverted triangles ; Total no . of K sized triangle ; Given N and K ; Function Call
function No_of_Triangle ( N , K ) { if ( N < K ) return - 1 ; else { let Tri_up = 0 ; Tri_up = Math . floor ( ( ( N - K + 1 ) * ( N - K + 2 ) ) / 2 ) ; let Tri_down = 0 ; Tri_down = Math . floor ( ( ( N - 2 * K + 1 ) * ( N - 2 * K + 2 ) ) / 2 ) ; return Tri_up + Tri_down ; } } let N = 4 , K = 2 ; document . write ( No_of_Triangle ( N , K ) ) ;