More progress
This commit is contained in:
27
solutions/other/reversemultiple9.php
Normal file
27
solutions/other/reversemultiple9.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
//Find a three-digit number such that when the digits are reversed and subtracted from the original number, the result is a multiple of 9.
|
||||
function numreverse($number) {
|
||||
|
||||
$numberStr = (string)$number;
|
||||
$numberStr = strrev($numberStr);
|
||||
return (int)$numberStr;
|
||||
}
|
||||
$i = 100;
|
||||
$good = 0;
|
||||
$bad = 0;
|
||||
while($i <=999) {
|
||||
$num = $i - numreverse($i);
|
||||
|
||||
if($num != 0 && $num % 9 == 0) {
|
||||
echo("\nFound $i");
|
||||
$good++;
|
||||
} else {
|
||||
echo("\nNo $i");
|
||||
$bad++;
|
||||
}
|
||||
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo "\nGood: $good Bad: $bad";
|
Reference in New Issue
Block a user