3v4l.org

run code in 300+ PHP versions simultaneously
<?php var_export(strpos('123456789', 8 .'')); exit; class SudokuSolver { const NUMBERS = "123456789"; protected $sudokuColumns; public function __construct ($sudoku) { $this->sudokuColumns = $sudoku; } // could be static as well public function printOut ($sudoku) { foreach ($sudoku as $column) { foreach ($column as $cell) { echo "|"; if (null !== $cell) { echo $cell; } else { echo " "; } } echo "|\n"; } } public function solve() { $this->checkConsistenz(); } protected function checkConsistenz () { $columns = $this->sudokuColumns; // check rows -> own method $rows = array(); foreach ($columns as $columnIndex => $column) { foreach ($column as $rowIndex => $cell) { $rows[$rowIndex][$columnIndex] = $cell; } //$this->printOut($rows); } foreach ($rows as $rowIndex => $row) { var_export($this->checkRow($rowIndex,$row)); } } protected function checkRow ($rowIndex, $row) { $numbers = self::NUMBERS; echo "checking $rowIndex..\n"; foreach ($row as $column) { if (null === $column) { continue; } echo "$column , $numbers\n" . var_export(strpos($numbers,$column),true); if (false === strpos($numbers,$column)) { return false; } $numbers = str_replace($col,'',$numbers); } return true; } } $sudoku = array(); $sudoku[] = array(null,3,null, null,null,null, null,null,null); $sudoku[] = array(null,null,null, 1,9,5, null,null,null); $sudoku[] = array(null,null,8, null,null,null, null,6,null); $sudoku[] = array(8,null,null, null,6,null, null,null,null); $sudoku[] = array(4,null,null, 8,null,null, null,null,1); $sudoku[] = array(null,null,null ,null,2,null, null,null,null); $sudoku[] = array(null,6,null, null,null,null, 2,8,null); $sudoku[] = array(null,null,null, 4,1,9, null,null,5); $sudoku[] = array(null,null,null, null,null,null, null,7,null); $sudokuSolver = new SudokuSolver($sudoku); //$sudokuSolver->printOut($sudoku); $sudokuSolver->solve($sudoku);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/YYMpS
function name:  (null)
number of ops:  35
compiled vars:  !0 = $sudoku, !1 = $sudokuSolver
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'var_export'
          1        INIT_FCALL                                               'strpos'
          2        SEND_VAL                                                 '123456789'
          3        SEND_VAL                                                 '8'
          4        DO_ICALL                                         $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
    4     7      > EXIT                                                     
   73     8*       ASSIGN                                                   !0, <array>
   74     9*       ASSIGN_DIM                                               !0
         10*       OP_DATA                                                  <array>
   75    11*       ASSIGN_DIM                                               !0
         12*       OP_DATA                                                  <array>
   76    13*       ASSIGN_DIM                                               !0
         14*       OP_DATA                                                  <array>
   77    15*       ASSIGN_DIM                                               !0
         16*       OP_DATA                                                  <array>
   78    17*       ASSIGN_DIM                                               !0
         18*       OP_DATA                                                  <array>
   79    19*       ASSIGN_DIM                                               !0
         20*       OP_DATA                                                  <array>
   80    21*       ASSIGN_DIM                                               !0
         22*       OP_DATA                                                  <array>
   81    23*       ASSIGN_DIM                                               !0
         24*       OP_DATA                                                  <array>
   82    25*       ASSIGN_DIM                                               !0
         26*       OP_DATA                                                  <array>
   84    27*       NEW                                              $14     'SudokuSolver'
         28*       SEND_VAR_EX                                              !0
         29*       DO_FCALL                                      0          
         30*       ASSIGN                                                   !1, $14
   86    31*       INIT_METHOD_CALL                                         !1, 'solve'
         32*       SEND_VAR_EX                                              !0
         33*       DO_FCALL                                      0          
         34*     > RETURN                                                   1

Class SudokuSolver:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YYMpS
function name:  __construct
number of ops:  4
compiled vars:  !0 = $sudoku
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        ASSIGN_OBJ                                               'sudokuColumns'
          2        OP_DATA                                                  !0
   13     3      > RETURN                                                   null

End of function __construct

Function printout:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 15
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/YYMpS
function name:  printOut
number of ops:  17
compiled vars:  !0 = $sudoku, !1 = $column, !2 = $cell
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1      > FE_RESET_R                                       $3      !0, ->15
          2    > > FE_FETCH_R                                               $3, !1, ->15
   20     3    > > FE_RESET_R                                       $4      !1, ->12
          4    > > FE_FETCH_R                                               $4, !2, ->12
   21     5    >   ECHO                                                     '%7C'
   22     6        TYPE_CHECK                                  1020          !2
          7      > JMPZ                                                     ~5, ->10
   23     8    >   ECHO                                                     !2
          9      > JMP                                                      ->11
   25    10    >   ECHO                                                     '+'
   20    11    > > JMP                                                      ->4
         12    >   FE_FREE                                                  $4
   28    13        ECHO                                                     '%7C%0A'
   19    14      > JMP                                                      ->2
         15    >   FE_FREE                                                  $3
   30    16      > RETURN                                                   null

End of function printout

Function solve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YYMpS
function name:  solve
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   INIT_METHOD_CALL                                         'checkConsistenz'
          1        DO_FCALL                                      0          
   35     2      > RETURN                                                   null

End of function solve

Function checkconsistenz:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 27
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 27
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 15
filename:       /in/YYMpS
function name:  checkConsistenz
number of ops:  29
compiled vars:  !0 = $columns, !1 = $rows, !2 = $column, !3 = $columnIndex, !4 = $cell, !5 = $rowIndex, !6 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   FETCH_OBJ_R                                      ~7      'sudokuColumns'
          1        ASSIGN                                                   !0, ~7
   41     2        ASSIGN                                                   !1, <array>
   42     3      > FE_RESET_R                                       $10     !0, ->15
          4    > > FE_FETCH_R                                       ~11     $10, !2, ->15
          5    >   ASSIGN                                                   !3, ~11
   43     6      > FE_RESET_R                                       $13     !2, ->13
          7    > > FE_FETCH_R                                       ~14     $13, !4, ->13
          8    >   ASSIGN                                                   !5, ~14
   44     9        FETCH_DIM_W                                      $16     !1, !5
         10        ASSIGN_DIM                                               $16, !3
         11        OP_DATA                                                  !4
   43    12      > JMP                                                      ->7
         13    >   FE_FREE                                                  $13
   42    14      > JMP                                                      ->4
         15    >   FE_FREE                                                  $10
   48    16      > FE_RESET_R                                       $18     !1, ->27
         17    > > FE_FETCH_R                                       ~19     $18, !6, ->27
         18    >   ASSIGN                                                   !5, ~19
   49    19        INIT_FCALL                                               'var_export'
         20        INIT_METHOD_CALL                                         'checkRow'
         21        SEND_VAR_EX                                              !5
         22        SEND_VAR_EX                                              !6
         23        DO_FCALL                                      0  $21     
         24        SEND_VAR                                                 $21
         25        DO_ICALL                                                 
   48    26      > JMP                                                      ->17
         27    >   FE_FREE                                                  $18
   51    28      > RETURN                                                   null

End of function checkconsistenz

Function checkrow:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 41
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 41
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/YYMpS
function name:  checkRow
number of ops:  44
compiled vars:  !0 = $rowIndex, !1 = $row, !2 = $numbers, !3 = $column, !4 = $col
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   55     2        ASSIGN                                                   !2, '123456789'
   56     3        ROPE_INIT                                     3  ~7      'checking+'
          4        ROPE_ADD                                      1  ~7      ~7, !0
          5        ROPE_END                                      2  ~6      ~7, '..%0A'
          6        ECHO                                                     ~6
   57     7      > FE_RESET_R                                       $9      !1, ->41
          8    > > FE_FETCH_R                                               $9, !3, ->41
   58     9    >   TYPE_CHECK                                    2          !3
         10      > JMPZ                                                     ~10, ->12
   59    11    > > JMP                                                      ->8
   61    12    >   ROPE_INIT                                     4  ~12     !3
         13        ROPE_ADD                                      1  ~12     ~12, '+%2C+'
         14        ROPE_ADD                                      2  ~12     ~12, !2
         15        ROPE_END                                      3  ~11     ~12, '%0A'
         16        INIT_FCALL                                               'var_export'
         17        INIT_FCALL                                               'strpos'
         18        SEND_VAR                                                 !2
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $14     
         21        SEND_VAR                                                 $14
         22        SEND_VAL                                                 <true>
         23        DO_ICALL                                         $15     
         24        CONCAT                                           ~16     ~11, $15
         25        ECHO                                                     ~16
   62    26        INIT_FCALL                                               'strpos'
         27        SEND_VAR                                                 !2
         28        SEND_VAR                                                 !3
         29        DO_ICALL                                         $17     
         30        TYPE_CHECK                                    4          $17
         31      > JMPZ                                                     ~18, ->34
   64    32    >   FE_FREE                                                  $9
         33      > RETURN                                                   <false>
   66    34    >   INIT_FCALL                                               'str_replace'
         35        SEND_VAR                                                 !4
         36        SEND_VAL                                                 ''
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $19     
         39        ASSIGN                                                   !2, $19
   57    40      > JMP                                                      ->8
         41    >   FE_FREE                                                  $9
   68    42      > RETURN                                                   <true>
   69    43*     > RETURN                                                   null

End of function checkrow

End of class SudokuSolver.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.04 ms | 1408 KiB | 19 Q