1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

What language you can use to solve the Sudoku Puzzle ?

Discussion in 'General Business' started by Hiryou, Nov 20, 2007.

  1. #1
    I think that many of you know very much about Sudoku puzzle game. Here is my first program to solve any Basic Sudoku Matrix (9*9 Matrix), I had written it so far in Javascript language. I know that many persons can do the similar thing very better than me, but here is my first gift I give all of you in this forum.
    So wish you would enjoy my Gift
    Javascript code :

    <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice" xmlns="http://www.w3.org/TR/REC-html40">

    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

    <title>Sudoku Solver</title>
    <script language="javascript">

    var a=new Array(82);
    range=new Array(82);
    cell=new Array(82);
    var blank,count,cont;
    blank=0; count=0; cont="";

    for (t=1;t<=81;t++) a[t]=0;
    for (t=1;t<=81;t++)
    {
    i=Math.floor((t-1)/9)+1;
    j=t-((i-1)*9);
    if (i>=1 && i<=3)
    {
    if (j>=1 && j<=3) range[t]=1;
    if (j>=4 && j<=6) range[t]=2;
    if (j>=7 && j<=9) range[t]=3;
    }
    if (i>=4 && i<=6)
    {
    if (j>=1 && j<=3) range[t]=4;
    if (j>=4 && j<=6) range[t]=5;
    if (j>=7 && j<=9) range[t]=6;
    }
    if (i>=7 && i<=9)
    {
    if (j>=1 && j<=3) range[t]=7;
    if (j>=4 && j<=6) range[t]=8;
    if (j>=7 && j<=9) range[t]=9;
    }
    }
    for (t=1;t<=81;t++) cell[t]=0;

    function Main_Programme()
    {
    for (i=1;i<=81;i++) {a=window.document.main.elements[i-1].value;}
    for (t=1;t<=81;t++)
    if (a[t]=="") a[t]=0
    else if (a[t]>=0 && a[t]<=9) a[t]=parseInt(a[t])
    else
    {
    alert(" Input data incorrect !");
    return false;
    }
    for (t=1;t<=81;t++) if (a[t]>0)
    {
    var temp=a[t];
    a[t]=0;
    if (Row(t,temp)==false || Col(t,temp)==false || Ran(t,temp)==false)
    {
    alert(" Input data incorrect !");
    return false;
    }
    a[t]=temp;
    }
    Make_List();
    Try(1);
    }

    function Make_List()
    {
    var temp;
    temp=0;
    for (t=1;t<=81;t++) if (a[t]==0)
    {
    temp=temp+1;
    cell[temp]=t;
    }
    blank=temp;
    }

    function Try(t)
    {
    var num;
    for (num=1;num<=9;num++) if (Row(cell[t],num)==true) if (Col(cell[t],num)==true) if (Ran(cell[t],num)==true)
    {
    a[cell[t]]=num;
    if (t==blank) {Out_Put()} else {Try(t+1)}
    if (cont=="y") break;
    a[cell[t]]=0;
    }
    }
    function Row(t,num)
    {
    d=Math.floor((t-1)/9)+1;
    for (c=1;c<=9;c++) if (a[((d-1)*9)+c]==num) return false;
    return true;
    }

    function Col(t,num)
    {
    d=Math.floor((t-1)/9)+1;
    c=t-((d-1)*9);
    for (d=1;d<=9;d++) if (a[((d-1)*9)+c]==num) return false;
    return true;
    }

    function Ran(t,num)
    {
    for (temp=1;temp<=81;temp++) if (range[temp]==range[t]) if (a[temp]==num) return false;
    return true;
    }

    function Out_Put()
    {
    for (i=1;i<=81;i++) {window.document.kq.elements[i-1].value=a;}
    window.document.kq.F82.focus();
    count++;
    window.document.kq.F82.value=" Result "+count.toString();
    cont=prompt(" Do you want to break here ( y ) ? ");
    }

    function Set_Reset()
    {
    blank=0; count=0;
    cont="";
    for (i=1;i<=81;i++)
    {
    window.document.main.elements[i-1].value="";
    window.document.kq.elements[i-1].value="";
    }
    window.document.kq.F82.value="";
    window.document.main.T1.focus();
    }

    </script>

    </head>
    <body>

    <p align="center"><font size="5"><b>Sudoku Solver</b></font></p>
    <form method="POST" action="--WEBBOT-SELF--" name="main">
    <table border="0" id="table1" p align=center width="339" height="257">
    <tr>
    <td align="center">
    <input type="text" name="T1" size="1">
    <input type="text" name="T2" size="1">
    <input type="text" name="T3" size="1"><br>
    <input type="text" name="T10" size="1">
    <input type="text" name="T11" size="1">
    <input type="text" name="T12" size="1"><br>
    <input type="text" name="T19" size="1">
    <input type="text" name="T20" size="1">
    <input type="text" name="T21" size="1"></td>
    <td align="center">
    <input type="text" name="T4" size="1">
    <input type="text" name="T5" size="1">
    <input type="text" name="T6" size="1"><br>
    <input type="text" name="T13" size="1">
    <input type="text" name="T14" size="1">
    <input type="text" name="T15" size="1"><br>
    <input type="text" name="T22" size="1">
    <input type="text" name="T23" size="1">
    <input type="text" name="T24" size="1"></td>
    <td align="center">
    <input type="text" name="T7" size="1">
    <input type="text" name="T8" size="1">
    <input type="text" name="T9" size="1"><br>
    <input type="text" name="T16" size="1">
    <input type="text" name="T17" size="1">
    <input type="text" name="T18" size="1"><br>
    <input type="text" name="T25" size="1">
    <input type="text" name="T26" size="1">
    <input type="text" name="T27" size="1"></td>
    </tr>
    <tr>
    <td align="center">
    <input type="text" name="T28" size="1">
    <input type="text" name="T29" size="1">
    <input type="text" name="T30" size="1"><br>
    <input type="text" name="T37" size="1">
    <input type="text" name="T38" size="1">
    <input type="text" name="T39" size="1"><br>
    <input type="text" name="T46" size="1">
    <input type="text" name="T47" size="1">
    <input type="text" name="T48" size="1"></td>
    <td align="center">
    <input type="text" name="T31" size="1">
    <input type="text" name="T32" size="1">
    <input type="text" name="T33" size="1"><br>
    <input type="text" name="T40" size="1">
    <input type="text" name="T41" size="1">
    <input type="text" name="T42" size="1"><br>
    <input type="text" name="T49" size="1">
    <input type="text" name="T50" size="1">
    <input type="text" name="T51" size="1"></td>
    <td align="center">
    <input type="text" name="T34" size="1">
    <input type="text" name="T35" size="1">
    <input type="text" name="T36" size="1"><br>
    <input type="text" name="T43" size="1">
    <input type="text" name="T44" size="1">
    <input type="text" name="T45" size="1"><br>
    <input type="text" name="T52" size="1">
    <input type="text" name="T53" size="1">
    <input type="text" name="T54" size="1"></td>
    </tr>
    <tr>
    <td align="center">
    <input type="text" name="T55" size="1">
    <input type="text" name="T56" size="1">
    <input type="text" name="T57" size="1"><br>
    <input type="text" name="T64" size="1">
    <input type="text" name="T65" size="1">
    <input type="text" name="T66" size="1"><br>
    <input type="text" name="T73" size="1">
    <input type="text" name="T74" size="1">
    <input type="text" name="T75" size="1"></td>
    <td align="center">
    <input type="text" name="T58" size="1">
    <input type="text" name="T59" size="1">
    <input type="text" name="T60" size="1"><br>
    <input type="text" name="T67" size="1">
    <input type="text" name="T68" size="1">
    <input type="text" name="T69" size="1"><br>
    <input type="text" name="T76" size="1">
    <input type="text" name="T77" size="1">
    <input type="text" name="T78" size="1"></td>
    <td align="center">
    <input type="text" name="T61" size="1">
    <input type="text" name="T62" size="1">
    <input type="text" name="T63" size="1"><br>
    <input type="text" name="T70" size="1">
    <input type="text" name="T71" size="1">
    <input type="text" name="T72" size="1"><br>
    <input type="text" name="T79" size="1">
    <input type="text" name="T80" size="1">
    <input type="text" name="T81" size="1"></td>
    </tr>
    </table>
    <p align="left"><b><font color="#FF0000" size="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href=# onclick="return Main_Programme();">Solve</a>&nbsp; <u><a href=# onclick="Set_Reset()">Reset</a></u></font></b></p>
    </form>

    <form method="POST" name="kq" action="--WEBBOT-SELF--">
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <table border="0" id="table2" p align=center width="339" height="257">
    <tr>
    <td align="center">
    <input type="text" name="F1" size="1">
    <input type="text" name="F2" size="1">
    <input type="text" name="F3" size="1"><br>
    <input type="text" name="F10" size="1">
    <input type="text" name="F11" size="1">
    <input type="text" name="F12" size="1"><br>
    <input type="text" name="F19" size="1">
    <input type="text" name="F20" size="1">
    <input type="text" name="F21" size="1"></td>
    <td align="center">
    <input type="text" name="F4" size="1">
    <input type="text" name="F5" size="1">
    <input type="text" name="F6" size="1"><br>
    <input type="text" name="F13" size="1">
    <input type="text" name="F14" size="1">
    <input type="text" name="F15" size="1"><br>
    <input type="text" name="F22" size="1">
    <input type="text" name="F23" size="1">
    <input type="text" name="F24" size="1"></td>
    <td align="center">
    <input type="text" name="F7" size="1">
    <input type="text" name="F8" size="1">
    <input type="text" name="F9" size="1"><br>
    <input type="text" name="F16" size="1">
    <input type="text" name="F17" size="1">
    <input type="text" name="F18" size="1"><br>
    <input type="text" name="F25" size="1">
    <input type="text" name="F26" size="1">
    <input type="text" name="F27" size="1"></td>
    </tr>
    <tr>
    <td align="center">
    <input type="text" name="F28" size="1">
    <input type="text" name="F29" size="1">
    <input type="text" name="F30" size="1"><br>
    <input type="text" name="F37" size="1">
    <input type="text" name="F38" size="1">
    <input type="text" name="F39" size="1"><br>
    <input type="text" name="F46" size="1">
    <input type="text" name="F47" size="1">
    <input type="text" name="F48" size="1"></td>
    <td align="center">
    <input type="text" name="F31" size="1">
    <input type="text" name="F32" size="1">
    <input type="text" name="F33" size="1"><br>
    <input type="text" name="F40" size="1">
    <input type="text" name="F41" size="1">
    <input type="text" name="F42" size="1"><br>
    <input type="text" name="F49" size="1">
    <input type="text" name="F50" size="1">
    <input type="text" name="F51" size="1"></td>
    <td align="center">
    <input type="text" name="F34" size="1">
    <input type="text" name="F35" size="1">
    <input type="text" name="F36" size="1"><br>
    <input type="text" name="F43" size="1">
    <input type="text" name="F44" size="1">
    <input type="text" name="F45" size="1"><br>
    <input type="text" name="F52" size="1">
    <input type="text" name="F53" size="1">
    <input type="text" name="F54" size="1"></td>
    </tr>
    <tr>
    <td align="center">
    <input type="text" name="F55" size="1">
    <input type="text" name="F56" size="1">
    <input type="text" name="F57" size="1"><br>
    <input type="text" name="F64" size="1">
    <input type="text" name="F65" size="1">
    <input type="text" name="F66" size="1"><br>
    <input type="text" name="F73" size="1">
    <input type="text" name="F74" size="1">
    <input type="text" name="F75" size="1"></td>
    <td align="center">
    <input type="text" name="F58" size="1">
    <input type="text" name="F59" size="1">
    <input type="text" name="F60" size="1"><br>
    <input type="text" name="F67" size="1">
    <input type="text" name="F68" size="1">
    <input type="text" name="F69" size="1"><br>
    <input type="text" name="F76" size="1">
    <input type="text" name="F77" size="1">
    <input type="text" name="F78" size="1"></td>
    <td align="center">
    <input type="text" name="F61" size="1">
    <input type="text" name="F62" size="1">
    <input type="text" name="F63" size="1"><br>
    <input type="text" name="F70" size="1">
    <input type="text" name="F71" size="1">
    <input type="text" name="F72" size="1"><br>
    <input type="text" name="F79" size="1">
    <input type="text" name="F80" size="1">
    <input type="text" name="F81" size="1"></td>
    </tr>
    </table>
    <p align="center"></p>
    <p>&nbsp;</p>
    <p align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="F82" size="15"></p>
    </form>
    <p>&nbsp;</p>

    </body>

    </html>
     
    Hiryou, Nov 20, 2007 IP
  2. magda

    magda Notable Member

    Messages:
    5,197
    Likes Received:
    315
    Best Answers:
    0
    Trophy Points:
    280
    #2
    Wow, that's really..ummmm.....wide :confused:
     
    magda, Nov 20, 2007 IP
  3. jobic

    jobic Peon

    Messages:
    321
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    While I probably can't make one of those scripts, not unless I invest at least a few hours in learning that language. I can solve sudoku's just as easily.

    Maybe not that fast, but still, I'm pretty fast :D hah
    Just got a new sudoku-book :) 192 puzzles ! That'll keep me going for a couple of weeks.

    Props to you for being able to make such a script.
    For you I take of my hat.

    greetz,
    jobic
     
    jobic, Nov 20, 2007 IP