Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A Su Doku solver

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60578] Re: A Su Doku solver
  • From: "Valeri Astanoff" <astanoff at yahoo.fr>
  • Date: Tue, 20 Sep 2005 06:16:21 -0400 (EDT)
  • References: <200509191007.GAA25694@smc.vnet.net><dgol73$hoa$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Thanks for the interesting counterexample :
I'm going to try and improve my program (if I can ! ).

For the amateurs, here is another small program
(that uses the first one) to generate grids at random:


In[5]:=
newgrid := Module[{g1={1,2,3}, g2={4,5,6}, g3={7,8,9},
        basegrid, testgrid, lastgrid, finalgrid, choices, indices},
      basegrid={
          {1,2,3,4,5,8,6,7,9},
          {5,9,6,2,1,7,3,8,4},
          {8,7,4,3,6,9,1,2,5},
          {2,8,9,1,4,3,7,5,6},
          {4,6,5,9,7,2,8,3,1},
          {7,3,1,6,8,5,4,9,2},
          {3,4,2,8,9,1,5,6,7},
          {6,5,8,7,2,4,9,1,3},
          {9,1,7,5,3,6,2,4,8}};
      testgrid = basegrid;
      While[FreeQ[testgrid,0],
        lastgrid = basegrid;
        basegrid[[Random[Integer,{1,9}],Random[Integer,{1,9}]]]=0;
        testgrid = sudoku[basegrid]];
      finalgrid = If[Random[]>0.5, lastgrid, Transpose[lastgrid]];
      choices=Select[Permutations[Range[9]],
        (((s1=Sort[#[[g1]]]) == g1||s1 == g2||s1 == g3)&&
         ((s2=Sort[#[[g2]]]) == g1||s2 == g2||s2 == g3)&&
         ((s3=Sort[#[[g3]]]) == g1||s3 == g2||s3 == g3))&];
      indices = choices[[Random[Integer,{1,Length[choices]}]]];
      finalgrid[[indices]]
      ];

In[6]:=newgrid

Out[6]=
{{3,4,2,8,0,0,5,0,7},
{0,1,7,0,3,6,2,4,8},
{0,5,0,7,2,0,0,0,0},
{0,0,0,0,0,0,7,5,0},
{0,6,0,0,0,2,8,3,1},
{7,3,1,0,0,0,0,9,0},
{0,0,3,0,5,8,0,7,9},
{8,7,4,3,0,9,0,0,5},
{0,0,0,0,0,0,0,8,0}}

In[7]:=sudoku[%]

Out[7]=
{{3,4,2,8,9,1,5,6,7},
{9,1,7,5,3,6,2,4,8},
{6,5,8,7,2,4,9,1,3},
{2,8,9,1,4,3,7,5,6},
{4,6,5,9,7,2,8,3,1},
{7,3,1,6,8,5,4,9,2},
{1,2,3,4,5,8,6,7,9},
{8,7,4,3,6,9,1,2,5},
{5,9,6,2,1,7,3,8,4}}


v.a.


  • Prev by Date: Re: Re: another Bug in Reduce ?
  • Next by Date: Re: NonlinearFit-Logistic Function-CalcCenter 3
  • Previous by thread: A Su Doku solver
  • Next by thread: Re: A Su Doku solver