array_search('2',$roster_array)) { return(0); } } // check to see if he outranks Snppaer if(in_array('4',$roster_array)) { if(array_search('3',$roster_array) > array_search('4',$roster_array)) { return(0); } } } // snapper rule1 // Snapper won't be Vice-President if($roster_array[1] == '4') { return(0); } // snapper rule 2 // Snapper won't be secretary if Mackerel is an officer if($roster_array[2] == '4' AND in_array('3',$roster_array)) { return(0); } // snapper rule 3 // Snapper won't serve with Grouper unless Bass serves too if(in_array('4',$roster_array) AND in_array('0',$roster_array)) { if(!in_array('5',$roster_array)) { return(0); } } // Bass rule // Bass won't serve unless either he or Ray is President if(in_array('5',$roster_array)) { if($roster_array[0] != '5' OR $roster_array[0] != '2') { return(0); } } // okay, we got this far, the combination must work // now, there is no rule that says one person can't fill two offices, but I'm assuming // Coudal meant to do this for($i = 0;$i < 6;$i++) { $test_array = array_keys($roster_array, "$i"); if(count($test_array) > 1) { return(0); } } return(1); } // Candidates $fish_array = array(0 => 'Mr. Grouper',1 => 'Dr. Trout',2 => 'Mr. Ray',3 => 'Mr. Mackerel',4 => 'The Snapper',5 => 'Mr. Bass'); // Offices $position_array = array(0 => 'President',1 => 'Vice-President',2 => 'Secretary'); // now, we just need to attack this with brute // force since the combinations are 5! x 4! X 3! $successes = 0; for($president = 0;$president < 6;$president++) { for($vice = 0;$vice < 6;$vice++) { for($secretary = 0;$secretary < 6;$secretary++) { $test_array = array(0 => $president,1 => $vice,2 => $secretary); if(test_combination($test_array)) { $successes++; echo "
Allowed Combination # $successes
"; for($i = 0;$i < 3;$i++) { echo $position_array[$i] . ": " . $fish_array[$test_array[$i]] . "
"; } } } } } ?>