Hosoya 's Triangle | JavaScript program to implement the above approach ; Base case ; Recursive step ; Print the Hosoya triangle of height n . ; Driver code
function Hosoya ( n , m ) { if ( ( n == 0 && m == 0 ) || ( n == 1 && m == 0 ) || ( n == 1 && m == 1 ) || ( n == 2 && m == 1 ) ) return 1 ; if ( n > m ) return Hosoya ( n - 1 , m ) + Hosoya ( n - 2 , m ) ; else if ( m == n ) return Hosoya ( n - 1 , m - 1 ) + Hosoya ( n - 2 , m - 2 ) ; else return 0 ; } function printHosoya ( n ) { for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j <= i ; j ++ ) document . write ( Hosoya ( i , j ) + " " ) ; document . write ( " " ) ; } } let n = 5 ; printHosoya ( n ) ;