From d3857b17a5345ff09cdc81e9e3732e906cc7754e Mon Sep 17 00:00:00 2001 From: gnieark Date: Wed, 18 Nov 2015 23:39:29 +0100 Subject: [PATCH] resolve all --- easy.txt | 2 +- gnieark.php | 71 +++++++++++++++++++++++++---------------------------- hard.txt | 2 +- medium.txt | 2 +- 4 files changed, 37 insertions(+), 40 deletions(-) diff --git a/easy.txt b/easy.txt index 79d364c..598e475 100755 --- a/easy.txt +++ b/easy.txt @@ -217,4 +217,4 @@ | 3 4| |4 1 2 | | 9 5 | -+-----------------+ ++-----------------+ \ No newline at end of file diff --git a/gnieark.php b/gnieark.php index de9625b..50a8eaf 100644 --- a/gnieark.php +++ b/gnieark.php @@ -1,6 +1,6 @@ " ")&&($i<81));$i++){ + $y=(int)($i/9); + $x=fmod($i,9); + } + if(($i==81)&&($grille[8][8]<>" ")){ + //la grille est déjà pleine + return $grille; + } + + //enregistrer toutes les possibilités sur cette case + $canPlay=false; + for($k=1;$k<10;$k++){ + if(canBePlaced($k,$x,$y,$grille)){ + //$possib[$x."-".$y][]=$k; + $canPlay=true; + $grilleTemp=$grille; + $grilleTemp[$y][$x]=$k; + if($gr=resolveSudokuByBruteforce($grilleTemp)){ + return $gr; + }else{ + //en fait, non , on ne peut pas jouer là $canPlay=false; - for($k=1;$k<10;$k++){ - if(canBePlaced($k,$x,$y,$grille)){ - //$possib[$x."-".$y][]=$k; - $canPlay=true; - $grilleTemp=$grille; - $grilleTemp[$y][$x]=$k; - if($gr=resolveSudokuByBruteforce($grilleTemp)){ - return $gr; - }else{ - //en fait, non , on ne peut pas jouer là - $canPlay=false; - } - } - } - - if(!$canPlay){ - return false; - } } - - - } } - /* - if(count($possib==1)){ - //y a qu'une case à jouer - list($x,$y)=explode("-",array_keys($possib)[0]); - $grilleTemp[$y][$x]=$possib[$x."-".$y][0]; - return $grilleTemp; + + if(!$canPlay){ + // echo "CAN'T:".$x." ".$y."\n"; + //viewGrid($grille); + return false; } - */ + + + } function resolveSudoku($grille){ @@ -78,6 +74,7 @@ function resolveSudoku($grille){ if($grid=resolveSudokuByBruteforce($grille)){ return $grid; }else{ + return $grille; } } diff --git a/hard.txt b/hard.txt index 90811df..8ddb16f 100755 --- a/hard.txt +++ b/hard.txt @@ -217,4 +217,4 @@ | 5 8 2 4 | | | |7 5 4 3 8 | -+-----------------+ ++-----------------+ \ No newline at end of file diff --git a/medium.txt b/medium.txt index 9030e05..0e1cd19 100755 --- a/medium.txt +++ b/medium.txt @@ -217,4 +217,4 @@ | 7 9| | 1 6 8| | 2 3 | -+-----------------+ ++-----------------+ \ No newline at end of file