Count n digit numbers not having a particular digit | PHP Implementation of above method ; Finding number of possible number with n digits excluding a particular digit ; Checking if number of digits is zero ; Checking if number of digits is one ; Checking if number of digits is odd ; Calling digitNumber function with ( digit - 1 ) / 2 digits ; ; Calling digitNumber function with n / 2 digits ; Calling digitNumber function Checking if excluding digit is zero or non - zero ; Initializing variables
< ? php $ mod = 1000000007 ; function digitNumber ( $ n ) { global $ mod ; if ( $ n == 0 ) return 1 ; if ( $ n == 1 ) return 9 ; if ( $ n % 2 != 0 ) { $ temp = digitNumber ( ( $ n - 1 ) / 2 ) % $ mod ; return ( 9 * ( $ temp * $ temp ) % $ mod ) % $ mod ; } else { $ temp = digitNumber ( $ n / 2 ) % $ mod ; return ( $ temp * $ temp ) % $ mod ; } } function countExcluding ( $ n , $ d ) { global $ mod ; if ( $ d == 0 ) return ( 9 * digitNumber ( $ n - 1 ) ) % $ mod ; else return ( 8 * digitNumber ( $ n - 1 ) ) % $ mod ; } $ d = 9 ; $ n = 3 ; print ( countExcluding ( $ n , $ d ) ) ; ? >