Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Digital-root/PHP/digital-root.php
Normal file
26
Task/Digital-root/PHP/digital-root.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
// Digital root
|
||||
|
||||
function rootAndPers($n, $bas)
|
||||
// Calculate digital root and persistance
|
||||
{
|
||||
$pers = 0;
|
||||
while ($n >= $bas) {
|
||||
$s = 0;
|
||||
do {
|
||||
$s += $n % $bas;
|
||||
$n = floor($n / $bas);
|
||||
} while ($n > 0);
|
||||
$pers++;
|
||||
$n = $s;
|
||||
}
|
||||
return array($n, $pers);
|
||||
}
|
||||
|
||||
foreach ([1, 14, 267, 8128, 39390, 588225, 627615] as $a) {
|
||||
list($root, $pers) = rootAndPers($a, 10);
|
||||
echo str_pad($a, 7, ' ', STR_PAD_LEFT);
|
||||
echo str_pad($pers, 6, ' ', STR_PAD_LEFT);
|
||||
echo str_pad($root, 6, ' ', STR_PAD_LEFT), PHP_EOL;
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue