3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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] = (string) $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 = 62) Position 1 = -2
filename:       /in/VfZcF
function name:  (null)
number of ops:  27
compiled vars:  !0 = $sudoku, !1 = $sudokuSolver
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   ASSIGN                                                   !0, <array>
   72     1        ASSIGN_DIM                                               !0
          2        OP_DATA                                                  <array>
   73     3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  <array>
   74     5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  <array>
   75     7        ASSIGN_DIM                                               !0
          8        OP_DATA                                                  <array>
   76     9        ASSIGN_DIM                                               !0
         10        OP_DATA                                                  <array>
   77    11        ASSIGN_DIM                                               !0
         12        OP_DATA                                                  <array>
   78    13        ASSIGN_DIM                                               !0
         14        OP_DATA                                                  <array>
   79    15        ASSIGN_DIM                                               !0
         16        OP_DATA                                                  <array>
   80    17        ASSIGN_DIM                                               !0
         18        OP_DATA                                                  <array>
   82    19        NEW                                              $12     'SudokuSolver'
         20        SEND_VAR_EX                                              !0
         21        DO_FCALL                                      0          
         22        ASSIGN                                                   !1, $12
   84    23        INIT_METHOD_CALL                                         !1, 'solve'
         24        SEND_VAR_EX                                              !0
         25        DO_FCALL                                      0          
         26      > RETURN                                                   1

Class SudokuSolver:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VfZcF
function name:  __construct
number of ops:  4
compiled vars:  !0 = $sudoku
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        ASSIGN_OBJ                                               'sudokuColumns'
          2        OP_DATA                                                  !0
   11     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/VfZcF
function name:  printOut
number of ops:  17
compiled vars:  !0 = $sudoku, !1 = $column, !2 = $cell
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1      > FE_RESET_R                                       $3      !0, ->15
          2    > > FE_FETCH_R                                               $3, !1, ->15
   18     3    > > FE_RESET_R                                       $4      !1, ->12
          4    > > FE_FETCH_R                                               $4, !2, ->12
   19     5    >   ECHO                                                     '%7C'
   20     6        TYPE_CHECK                                  1020          !2
          7      > JMPZ                                                     ~5, ->10
   21     8    >   ECHO                                                     !2
          9      > JMP                                                      ->11
   23    10    >   ECHO                                                     '+'
   18    11    > > JMP                                                      ->4
         12    >   FE_FREE                                                  $4
   26    13        ECHO                                                     '%7C%0A'
   17    14      > JMP                                                      ->2
         15    >   FE_FREE                                                  $3
   28    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/VfZcF
function name:  solve
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_METHOD_CALL                                         'checkConsistenz'
          1        DO_FCALL                                      0          
   33     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 = 16
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 28
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 28
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 16
filename:       /in/VfZcF
function name:  checkConsistenz
number of ops:  30
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
-------------------------------------------------------------------------------------
   37     0  E >   FETCH_OBJ_R                                      ~7      'sudokuColumns'
          1        ASSIGN                                                   !0, ~7
   39     2        ASSIGN                                                   !1, <array>
   40     3      > FE_RESET_R                                       $10     !0, ->16
          4    > > FE_FETCH_R                                       ~11     $10, !2, ->16
          5    >   ASSIGN                                                   !3, ~11
   41     6      > FE_RESET_R                                       $13     !2, ->14
          7    > > FE_FETCH_R                                       ~14     $13, !4, ->14
          8    >   ASSIGN                                                   !5, ~14
   42     9        CAST                                          6  ~18     !4
         10        FETCH_DIM_W                                      $16     !1, !5
         11        ASSIGN_DIM                                               $16, !3
         12        OP_DATA                                                  ~18
   41    13      > JMP                                                      ->7
         14    >   FE_FREE                                                  $13
   40    15      > JMP                                                      ->4
         16    >   FE_FREE                                                  $10
   46    17      > FE_RESET_R                                       $19     !1, ->28
         18    > > FE_FETCH_R                                       ~20     $19, !6, ->28
         19    >   ASSIGN                                                   !5, ~20
   47    20        INIT_FCALL                                               'var_export'
         21        INIT_METHOD_CALL                                         'checkRow'
         22        SEND_VAR_EX                                              !5
         23        SEND_VAR_EX                                              !6
         24        DO_FCALL                                      0  $22     
         25        SEND_VAR                                                 $22
         26        DO_ICALL                                                 
   46    27      > JMP                                                      ->18
         28    >   FE_FREE                                                  $19
   49    29      > 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/VfZcF
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
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   53     2        ASSIGN                                                   !2, '123456789'
   54     3        ROPE_INIT                                     3  ~7      'checking+'
          4        ROPE_ADD                                      1  ~7      ~7, !0
          5        ROPE_END                                      2  ~6      ~7, '..%0A'
          6        ECHO                                                     ~6
   55     7      > FE_RESET_R                                       $9      !1, ->41
          8    > > FE_FETCH_R                                               $9, !3, ->41
   56     9    >   TYPE_CHECK                                    2          !3
         10      > JMPZ                                                     ~10, ->12
   57    11    > > JMP                                                      ->8
   59    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
   60    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
   62    32    >   FE_FREE                                                  $9
         33      > RETURN                                                   <false>
   64    34    >   INIT_FCALL                                               'str_replace'
         35        SEND_VAR                                                 !4
         36        SEND_VAL                                                 ''
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $19     
         39        ASSIGN                                                   !2, $19
   55    40      > JMP                                                      ->8
         41    >   FE_FREE                                                  $9
   66    42      > RETURN                                                   <true>
   67    43*     > RETURN                                                   null

End of function checkrow

End of class SudokuSolver.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.49 ms | 1408 KiB | 19 Q