Count even length binary sequences with same sum of first and second half bits | diff is difference between sums first n bits and last n bits respectively ; We can 't cover difference of  more than n with 2n bits ; n == 1 , i . e . , 2 bit long sequences ; First bit is 0 & last bit is 1 ; First and last bits are same ; First bit is 1 & last bit is 0 ; Driver Code
< ? php function countSeq ( $ n , $ diff ) { if ( abs ( $ diff ) > $ n ) return 0 ; if ( $ n == 1 && $ diff == 0 ) return 2 ; if ( $ n == 1 && abs ( $ diff ) == 1 ) return 1 ; $ res = countSeq ( $ n - 1 , $ diff + 1 ) + 2 * countSeq ( $ n - 1 , $ diff ) + countSeq ( $ n - 1 , $ diff - 1 ) ; return $ res ; } $ n = 2 ; echo " Count ▁ of ▁ sequences ▁ is ▁ " , countSeq ( $ n , 0 ) ; ? >