Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: consecutive numbers (with wildcards between) detection

1. ## consecutive numbers (with wildcards between) detection

I'm coding an online game and the cards have values from 1-12 and there can be wild cards for any given number... how can i make a function that will detect a "Run of #" including wilds without manually making an if/else statement for each combination that is possible??

• this is what i have tried so far and it ALWAYS comes back with FAILED

PHP Code:
``` function isRun(\$numbervalues,\$num_wilds){     sort(\$numbervalues,SORT_NUMERIC);     \$nextnumber = \$numbervalues[0]+1;     \$newnumberset=array();     for(\$i=1;\$i<count(\$numbervalues);\$i++){         array_push(\$newnumberset,\$numbervalues[\$i]);     }     if(in_array(\$nextnumber,\$numbervalues)){         //we're advancing!         //start the function again with "next number" and same number of wild cards         if(isRun(\$newnumberset,\$num_wilds)){             return true;         }else{             return false;         }     }elseif(\$num_wilds >0){         \$new_wildcount=\$num_wilds-1;         //put a wild in for "next number"         //start the function again with "next number" and one less wild card         if(isRun(\$newnumberset,\$new_wildcount)){             return true;         }else{             return false;         }     }else{         return false;     } } \$thenumbers = array(2,3,6); //this array is missing 4 and 5 to form the complete run \$wilds=2; //these 2 wilds should take the place of 4 and 5 in this run if(!isRun(\$thenumbers,\$wilds)){     echo "Failed"; }else{     echo "Success!"; }  ```

• Your function was a bit bloated. Here's my version (with a bit of help from a friend):

PHP Code:
``` function isRun2(\$number_values,\$num_wilds) {     sort(\$number_values,SORT_NUMERIC);     for(\$i=\$number_values[0];\$i<end(\$number_values);\$i++) {         if(!in_array(\$i,\$number_values)) {             if((\$num_wilds--)==0) {                 return false;             }         }     }     return true; } \$numbers=array(2,4,5,7); \$wilds=2; if(isRun2(\$numbers,\$wilds)) {     echo "Success!"; } else {     echo "Failed!"; }  ```

• sweet! thanks. (and yea, i figured mine was bloated because i just was adding/removing stuff from it trying to get it to work). yours worked. thanks again!

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•