Skip to content

Commit c8a0171

Browse files
committed
small changes
1 parent 4995cd8 commit c8a0171

File tree

1 file changed

+25
-57
lines changed

1 file changed

+25
-57
lines changed

sudoku.js

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,32 @@ var checkBlock = require('./checkBlock.js');
55
var boardString = " 94 3 61 8 4 8 4 1 3 264 54 687 92 761 4 5 7 3 8 6 54 7 96 ";
66
var boardArray = boardString.split('');
77
var cycleCount=0;
8+
var doneArray; //to pass from findOptions to logSingleton
89

910

1011
databuilder(boardArray, findOptions);
12+
//set iteration control
1113

12-
function findOptions(fullArray){
13-
var row, col;
14-
for (row=0; row<9; row++)
15-
{
16-
for (col=0; col<9; col++)
17-
{ //console.log("------------------");
18-
// console.log("row is " + row + " and col is " + col + " value is "
19-
// + fullArray[row][col].value + " and block is " + fullArray[row][col].block);
20-
if (fullArray[row][col].value === null)
21-
{
22-
checkRow(row,col,fullArray); //assemble and return possible values
23-
checkCol(row,col,fullArray); //assemble and return possible values
24-
temprow=row+1;
25-
tempcol=col+1;
26-
boxDeletePossibles(fullArray[row][col].possibles, checkBlock(temprow, tempcol, fullArray)); //assemble and return possible values
27-
}
28-
}
29-
}
14+
logSingletonValues(doneArray);
15+
16+
function iterationControl(itNum, fullArray){
17+
var i = itNum;
18+
19+
for (i=0; i<itNum; i++)
20+
{ console.log("iteration Number is " + i + " of " + itNum);
21+
22+
findOptions();
23+
24+
logSingletonValues(doneArray);
25+
26+
insertSingletonValues(doneArray);
27+
}
28+
};
3029

31-
insertSingletonValues(fullArray);
32-
//logSingletonValues(fullArray);
33-
console.log(fullArray[3][1] )
3430

3531

36-
};
3732

38-
function findOptions2(fullArray){
33+
function findOptions(fullArray){
3934
var row, col;
4035
for (row=0; row<9; row++)
4136
{
@@ -53,20 +48,13 @@ function findOptions2(fullArray){
5348
}
5449
}
5550
}
56-
57-
//insertSingletonValues(fullArray);
51+
insertSingletonValues(fullArray);
5852
logSingletonValues(fullArray);
5953
console.log(fullArray[3][1] )
60-
61-
54+
doneArray = fullArray;
6255
};
6356

64-
65-
66-
67-
68-
69-
57+
7058
function logSingletonValues(fullArray){
7159
//iterate through big array
7260
var row, col;
@@ -78,18 +66,19 @@ function logSingletonValues(fullArray){
7866
{
7967
if (fullArray[row][col].possibles.length === 1)
8068
{
81-
console.log(fullArray[row][col].possibles + " is possibles. xxxxxx" +
69+
console.log(fullArray[row][col].possibles + " is possibles. xxxxxx " +
8270
fullArray[row][col].x + " zzzzz " + fullArray[row][col].y );
8371
}
8472
}
8573
}
8674
}
8775

88-
8976
function insertSingletonValues(fullArray){
9077
//iterate through big array
9178
var row, col;
9279
var lengthOne=0;
80+
countCycle = countCycle +1;
81+
if (countCycle > countCycleLimit) {return};
9382

9483
for (row=0; row<9; row++)
9584
{
@@ -98,31 +87,10 @@ function insertSingletonValues(fullArray){
9887
if (fullArray[row][col].possibles.length === 1)
9988
{
10089
fullArray[row][col].value = fullArray[row][col].possibles[0];
101-
lengthOne = lengthOne +1;
102-
90+
lengthOne = lengthOne +1;
10391
}
10492
}
105-
10693
}
107-
findOptions2(fullArray);
108-
109-
// if (lengthOne=0){
110-
111-
// console.log("the fullArray is " + fullArray);
112-
113-
114-
115-
// }
116-
// else
117-
// {
118-
// cycleCount =cycleCount+1;
119-
// if (cycleCount < 100)
120-
// {
121-
// findOptions(fullArray);
122-
// console.log(" we are call findOptions ");
123-
// }
124-
// }
125-
12694
};
12795

12896

0 commit comments

Comments
 (0)