For a coursework assignment I have to investigate this thing where you do the following for example:
264 - Choose 3 digits that are not the same 12 - Find the sum of them. 264 246 624 642 426 462 - List all the possible combinations of those digits _____ 2664 - Add the combinations 2664 / 12 = 222 - Divide the answer by the sum of the three digits and you allways get 222! To speed up the process of finding any exceptions if any, I thought id use php to do this, however i get a problem, the script runs without any coding errors, but it doesnt do what i want it to do - instead of returning any three digit combo that doesnt return 222, it just prints EVERY combo whice passes my conditional statement to weed out numbers that have digits where 2 or more are the same. Here is my code: <?php for ($i = 012; $i < 987; $i ++) { $comma = chunk_split($i, 1, ","); $split = explode(",", $comma); if ($split[0] == $split[1] || $split[0] == $split[2] || $split[1] == $split[2]) { } else{ $digitstotal = $split[0] + $split[1] + $split[2]; $num1 = "$split[0].$split[1].$split[2]"; $num2 = "$split[0].$split[2].$split[1]"; $num3 = "$split[1].$split[0].$split[2]"; $num4 = "$split[1].$split[2].$split[0]"; $num5 = "$split[2].$split[0].$split[1]"; $num6 = "$split[2].$split[1].$split[0]"; $numtotal = $num1 + $num2 + $num3 + $num4 + $num5 + $num6; $answer = $numtotal / $digitstotal; if ($answer != 222) { echo("$i does not return 222!<br>"); } } } ?> What is wrong with it? Any help at all is greatly apreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php