Well, since it's for school I'll only point out a couple of issues... - your for loop will never test the number 987 even though it should.
- add the following line rightr after you compute $numtotal: print("$numtotal = $num1 + $num2 + $num3 + $num4 + $num5 + $num6\n"); and you'll see that you'll get output like: 28.6 = 2.6.5 + 2.5.6 + 6.2.5 + 6.5.2 + 5.2.6 + 5.6.2 which should help you understand why it's not doing what you think it's doing. good luck. On Wed, 2 Oct 2002 [EMAIL PROTECTED] wrote: > 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 > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php