Alicia Posted January 28, 2010 Share Posted January 28, 2010 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; ?> Link to comment https://forums.phpfreaks.com/topic/190129-missing-values/ Share on other sites More sharing options...
jskywalker Posted January 28, 2010 Share Posted January 28, 2010 i see: Numbers matching the pattern "AABC": 0012 0013 0014 0015 0016 0017 0018 0019 0023 0024 0025 0026 0027 0028.................. 2259 2267 2268 2269 2278 2279 2289 3345 3346 3347 3348 3349 3356 3357 3358 3359 3367 3368 3369 3378 3379 3389 4456 4457 4458 4459 4467 4468 4469 4478 4479 4489 5567 5568 5569 5578 5579 5589 6678 6679 6689 7789 (above numbers where 1 on a line....) so, can you please explain what you where expecting? Link to comment https://forums.phpfreaks.com/topic/190129-missing-values/#findComment-1003210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.