Missing results

Hi,

Can some guru please advise how should I go about to fix these issues :

  • AABC & AAAB are not displaying the results that supposed to be there. Can you please give me an idea what I suppose to edit so all all numbers will be displayed. Thank you
<?php
$patterns = array('AAAA', 'AAAB', 'AABB', 'AABC', 'ABCD');
for ($i = 0; $i < count($patterns); $i++) {
    echo 'Numbers matching the pattern "'.$patterns[$i].'":<br>';
    $count = processPattern('', $patterns[$i]);
    $total[$i] = $count;
    echo '<br>';
}
 
function processPattern($replace, $remaining) {
    if ($remaining == '') {
        echo $replace.'<br>';
		
        return 1;
    }
    $char = preg_replace('/([a-zA-Z]).*/', '$1', $remaining);
    $toReplace = preg_replace('/('.$char.'*).*/', '$1', $remaining);
    $remaining = preg_replace('/'.$toReplace.'(.*)/', '$1', $remaining);
    $start = ($replace > '') ? intval(substr($replace, -1, 1)) + 1 : 0;
    $count = 0;
	for($i = $start; $i <= 9; $i++) {
        $count += processPattern($replace.str_repeat($i, strlen($toReplace)), $remaining);
    }
    return $count;
}
 
echo 'Totals for each pattern<br>';
$totalCount = 0;
for ($i = 0; $i < count($patterns); $i++) {
    echo $patterns[$i] . ': ' . $total[$i] . '<br>';
    $totalCount += $total[$i];
}
echo '<br>';
echo 'All found in total: ' . $totalCount;
?>

If you want help you might want to explain what the code is supposed to do, how it’s supposed to work, and exactly how it’s failing.

It’s pretty difficult to figure out what the code is supposed to do when it consists of a generically named recursive function with an unknown defect.