3v4l.org

run code in 500+ 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));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DEH9f
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                                   'print_r'
          1        INIT_FCALL                                                   'decompose'
          2        SEND_VAL                                                     11
          3        DO_FCALL                                          0  $0      
          4        SEND_VAR                                                     $0
          5        DO_ICALL                                                     
          6      > RETURN                                                       1

Function decompose:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 13
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 42
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 42
Branch analysis from position: 52
Branch analysis from position: 42
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 19
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 13
Branch analysis from position: 39
Branch analysis from position: 13
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 24, Position 2 = 29
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 33
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 19
Branch analysis from position: 36
Branch analysis from position: 19
Branch analysis from position: 29
filename:       /in/DEH9f
function name:  decompose
number of ops:  54
compiled vars:  !0 = $value, !1 = $dp, !2 = $i, !3 = $j, !4 = $result, !5 = $curr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        ASSIGN_OP                                         3          !0, !0
    5     2        INIT_FCALL                                                   'array_fill'
          3        SEND_VAL                                                     0
          4        ADD                                                  ~7      !0, 1
          5        SEND_VAL                                                     ~7
          6        SEND_VAL                                                     -1
          7        DO_ICALL                                             $8      
          8        ASSIGN                                                       !1, $8
    6     9        ASSIGN_DIM                                                   !1, 1
         10        OP_DATA                                                      1
    7    11        ASSIGN                                                       !2, 2
         12      > JMP                                                          ->37
    8    13    >   INIT_FCALL                                                   'sqrt'
         14        SEND_VAR                                                     !2
         15        DO_ICALL                                             $12     
         16        CAST                                              4  ~13     $12
         17        ASSIGN                                                       !3, ~13
         18      > JMP                                                          ->34
    9    19    >   MUL                                                  ~15     !3, !3
         20        SUB                                                  ~16     !2, ~15
         21        FETCH_DIM_R                                          ~17     !1, ~16
         22        IS_NOT_EQUAL                                         ~18     ~17, -1
         23      > JMPZ_EX                                              ~18     ~18, ->29
         24    >   MUL                                                  ~19     !3, !3
         25        SUB                                                  ~20     !2, ~19
         26        FETCH_DIM_R                                          ~21     !1, ~20
         27        IS_SMALLER                                           ~22     ~21, !3
         28        BOOL                                                 ~18     ~22
         29    > > JMPZ                                                         ~18, ->33
   10    30    >   ASSIGN_DIM                                                   !1, !2
         31        OP_DATA                                                      !3
   11    32      > JMP                                                          ->36
    8    33    >   PRE_DEC                                                      !3
         34    >   IS_SMALLER_OR_EQUAL                                          1, !3
         35      > JMPNZ                                                        ~25, ->19
    7    36    >   PRE_INC                                                      !2
         37    >   IS_SMALLER_OR_EQUAL                                          !2, !0
         38      > JMPNZ                                                        ~27, ->13
   16    39    >   ASSIGN                                                       !4, <array>
   17    40        ASSIGN                                                       !5, !0
   19    41      > JMP                                                          ->49
   20    42    >   FETCH_DIM_R                                          ~31     !1, !5
         43        ASSIGN_DIM                                                   !4
         44        OP_DATA                                                      ~31
   21    45        FETCH_DIM_R                                          ~32     !1, !5
         46        FETCH_DIM_R                                          ~33     !1, !5
         47        MUL                                                  ~34     ~32, ~33
         48        ASSIGN_OP                                         2          !5, ~34
   19    49    >   FETCH_DIM_R                                          ~36     !1, !5
         50        IS_NOT_EQUAL                                                 ~36, -1
         51      > JMPNZ                                                        ~37, ->42
   24    52    > > RETURN                                                       !4
   25    53*     > RETURN                                                       null

End of function decompose

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.53 ms | 2239 KiB | 17 Q