mozy contest: problem 2 PHP solution
Nicholas Leippe
nick at leippe.com
Mon Nov 6 10:03:25 MST 2006
The second problem gave one number per line.
For each number, output (sorted descending) all smaller positive integers that
were both multiples of 7 and whose reverse (string) was also a multiple of 7.
<?
while ($line = fgets(STDIN)) {
$n = (int) $line;
$res = array();
$i = $n;
while (!isMultof7($i)) {
$i--;
}
for (; $i >= 0; $i -= 7) {
if (isMultof7((int) strrev($i)))
{
echo "$i\n";
}
}
}
function isMultof7($i) {
$d = (int) ($i / 7);
return $d * 7 == $i;
}
More information about the PLUG
mailing list