- https://www.codewars.com/kata/5842df8ccbd22792a4000245 Write Number in Expanded Form.
Started at 22:58 22.10.2020 Thursday Oct.
Finished at 23:23 22.10.2020 Thursday Oct. (0hs 25minutes)
<?php | |
# https://www.codewars.com/kata/5842df8ccbd22792a4000245 Write Number in Expanded Form. | |
function expanded_form(int $n): string { | |
$ans = []; $power = 0; | |
while($n > 10){ | |
$x = $n % 10; | |
array_unshift($ans,[$x,$power]); | |
$power += 1; | |
$n = intval(substr(sprintf('%d',$n),0,-1)); | |
} | |
array_unshift($ans, [$n,$power]); | |
$ans = array_filter($ans,fn($x)=>$x[0] == 0 ? false : true); | |
return imploder($ans); | |
} | |
function imploder($arr){ | |
$answer = ""; | |
foreach($arr as $pair) $answer .= " + ".strval($pair[0]) . str_repeat("0",$pair[1]); | |
return trim($answer, " +"); | |
} |
Started at 22:58 22.10.2020 Thursday Oct.
Finished at 23:23 22.10.2020 Thursday Oct. (0hs 25minutes)