Cases where all remaining digits are 4 or 7 ( Remaining sum of digits should be multiple of 4 or 7 )
if ( $ sum % 7 == 0 ) { $ b ++ ; $ sum -= 7 ; } else if ( $ sum % 4 == 0 ) { $ a ++ ; $ sum -= 4 ; }