Hosoya 's Triangle | PHP Program to print Hosoya 's triangle of height n. ; Base case ; Recursive step ; Print the Hosoya triangle of height n . ; Driven Code
< ? php function Hosoya ( int $ n , int $ 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 ( $ i = 0 ; $ i < $ n ; $ i ++ ) { for ( $ j = 0 ; $ j <= $ i ; $ j ++ ) echo Hosoya ( $ i , $ j ) , " ▁ " ; echo " STRNEWLINE " ; } } $ n = 5 ; printHosoya ( $ n ) ; ? >