3v4l.org

run code in 300+ PHP versions simultaneously
<?php function decompose($value){ $value *= $value; $dp = array_fill(0,$value + 1,-1); $dp[1] = 1; for($i = 2; $i <= $value; ++$i){ for($j = intval( sqrt($i) ); $j >= 1; --$j){ if($dp[$i - $j * $j] != -1 && $dp[$i - $j * $j] < $j){ // meaning can be represented as sum of squares $dp[$i] = $j; break; // since we are looking for sequence with greater numbers } } } $result = []; $curr = $value; while($dp[$curr] != -1){ $result[] = $dp[$curr]; $curr -= $dp[$curr] * $dp[$curr]; } return $result; } print_r(decompose(11));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => 10 [1] => 4 [2] => 2 [3] => 1 )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
159.27 ms | 405 KiB | 5 Q