Number of pairs with Pandigital Concatenation | Checks if a given $is Pandigital ; digit i is not present thus not pandigital ; Returns number of pairs of strings resulting in Pandigital Concatenations ; iterate over all pair of strings ; Driver code
< ? php function isPanDigital ( $ s ) { $ digits = array ( ) ; $ digits = array_fill ( 0 , 10 , false ) ; for ( $ i = 0 ; $ i < strlen ( $ s ) ; $ i ++ ) $ digits [ ord ( $ s [ $ i ] ) - ord ( '0' ) ] = true ; for ( $ i = 0 ; $ i <= 9 ; $ i ++ ) if ( $ digits [ $ i ] == false ) return false ; return true ; } function countPandigitalPairs ( & $ v ) { $ pairs = 0 ; for ( $ i = 0 ; $ i < count ( $ v ) ; $ i ++ ) { for ( $ j = $ i + 1 ; $ j < count ( $ v ) ; $ j ++ ) { if ( isPanDigital ( $ v [ $ i ] . $ v [ $ j ] ) ) { $ pairs ++ ; } } } return $ pairs ; } $ v = array ( "123567" , "098234" , "14765" , "19804" ) ; echo ( countPandigitalPairs ( $ v ) ) ; ? >