99define ("N " , 9 );
1010define ("UNASSIGNED " , 0 );
1111
12- function  SolveSudoku (array  &$ gridbool  {
12+ function  solveSudoku (array  &$ gridbool  {
1313    $ row$ col0 ;
1414
15-     if  (!FindUnassignedLocation ($ grid$ row$ col
15+     if  (!findUnassignedLocation ($ grid$ row$ col
1616	return  true ; // success! no empty space 
1717
1818    for  ($ num1 ; $ num$ num
1919	if  (isSafe ($ grid$ row$ col$ num
2020	    $ grid$ row$ col$ num// make tentative assignment 
2121
22- 	    if  (SolveSudoku ($ grid
22+ 	    if  (solveSudoku ($ grid
2323		return  true ;  // return, if success// return, if success 
2424
2525	    $ grid$ row$ colUNASSIGNED ;  // failure, unmake & try again 
@@ -28,23 +28,23 @@ function SolveSudoku(array &$grid): bool {
2828    return  false ; // triggers backtracking 
2929}
3030
31- function  FindUnassignedLocation (array  &$ gridint  &$ rowint  &$ colbool  {
31+ function  findUnassignedLocation (array  &$ gridint  &$ rowint  &$ colbool  {
3232    for  ($ row0 ; $ row$ row
3333	for  ($ col0 ; $ col$ col
3434	    if  ($ grid$ row$ colUNASSIGNED )
3535		return  true ;
3636    return  false ;
3737}
3838
39- function  UsedInRow (array  &$ gridint  $ rowint  $ numbool  {
39+ function  usedInRow (array  &$ gridint  $ rowint  $ numbool  {
4040    return  in_array ($ num$ grid$ row
4141}
4242
43- function  UsedInColumn (array  &$ gridint  $ colint  $ numbool  {
43+ function  usedInColumn (array  &$ gridint  $ colint  $ numbool  {
4444    return  in_array ($ numarray_column ($ grid$ col
4545}
4646
47- function  UsedInBox (array  &$ gridint  $ boxStartRowint  $ boxStartColint  $ numbool  {
47+ function  usedInBox (array  &$ gridint  $ boxStartRowint  $ boxStartColint  $ numbool  {
4848    for  ($ row0 ; $ row3 ; $ row
4949	for  ($ col0 ; $ col3 ; $ col
5050	    if  ($ grid$ row$ boxStartRow$ col$ boxStartCol$ num
@@ -54,9 +54,9 @@ function UsedInBox(array &$grid, int $boxStartRow, int $boxStartCol, int $num):b
5454
5555function  isSafe (array  $ gridint  $ rowint  $ colint  $ numbool  {
5656
57-     return  !UsedInRow ($ grid$ row$ num
58- 	    !UsedInColumn ($ grid$ col$ num
59- 	    !UsedInBox ($ grid$ row$ row3 , $ col$ col3 , $ num
57+     return  !usedInRow ($ grid$ row$ num
58+ 	    !usedInColumn ($ grid$ col$ num
59+ 	    !usedInBox ($ grid$ row$ row3 , $ col$ col3 , $ num
6060}
6161
6262/* A utility function to print grid  */ 
@@ -80,7 +80,7 @@ function printGrid(array $grid) {
8080    [0 , 0 , 2 , 0 , 9 , 0 , 5 , 0 , 0 ]
8181];
8282
83- if  (SolveSudoku ($ gridtrue )
83+ if  (solveSudoku ($ gridtrue )
8484    printGrid ($ grid
8585else 
8686    echo  "No solution exists " ;
0 commit comments