text: Count ways to reach a score using 1 and 2 with no consecutive 2 s | A simple recursive implementation for counting ways to reach a score using 1 and 2 with consecutive 2 allowed ; base cases ; For cases n > 2 ; Driver Code
code: < ? php function CountWays ( $ n ) { if ( $ n == 0 ) { return 1 ; } if ( $ n == 1 ) { return 1 ; } if ( $ n == 2 ) { return 1 + 1 ; } return CountWays ( $ n - 1 ) + CountWays ( $ n - 3 ) ; } $ n = 5 ; echo CountWays ( $ n ) ; ? >