Hosoya 's Triangle | Javascript Program to print Hosoya 's triangle of height n. ; Print the Hosoya triangle of height n . ; base case . ; For each row . ; for each column ; ; recursive steps . ; printing the solution ; Driven Program
var N = 5 function printHosoya ( n ) { var dp = Array . from ( Array ( N ) , ( ) => Array ( N ) . fill ( 0 ) ) ; dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1 ; for ( var i = 2 ; i < n ; i ++ ) { for ( var j = 0 ; j < n ; j ++ ) { if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ; else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ; } } for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j <= i ; j ++ ) document . write ( dp [ i ] [ j ] + " " ) ; document . write ( " " ) ; } } var n = 5 ; printHosoya ( n ) ;