Skip to content

Commit 254223c

Browse files
committed
merge
1 parent c22233e commit 254223c

File tree

1 file changed

+88
-40
lines changed

1 file changed

+88
-40
lines changed

sudoku.js

Lines changed: 88 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@ databuilder(boardArray, findOptions);
1515
console.log('AFTER: ');
1616
printer(boardArray);
1717

18+
databuilder(boardArray, findOptions);
19+
20+
function findOptions(fullArray){
21+
var row, col;
22+
for (row=0; row<9; row++)
23+
{
24+
for (col=0; col<9; col++) {
25+
//console.log('row: ',row,'col: ',col);
26+
//console.log("------------------");
27+
// console.log("row is " + row + " and col is " + col + " value is "
28+
// + fullArray[row][col].value + " and block is " + fullArray[row][col].block);
29+
if (fullArray[row][col].value === null) {
30+
checkRow(row,col,fullArray); //assemble and return possible values
31+
checkCol(row,col,fullArray); //assemble and return possible values
32+
temprow=row+1;
33+
tempcol=col+1;
34+
boxDeletePossibles(fullArray[row][col].possibles, checkBlock(temprow, tempcol, fullArray)); //assemble and return possible values
35+
}
36+
}
37+
}
38+
insertSingletonValues(fullArray);
39+
//logSingletonValues(fullArray);
40+
//console.log(fullArray[3][1] )
41+
};
42+
1843
function findOptions(fullArray){
1944
var row, col;
2045
for (row=0; row<9; row++)
@@ -25,18 +50,19 @@ function findOptions(fullArray){
2550
// + fullArray[row][col].value + " and block is " + fullArray[row][col].block);
2651
if (fullArray[row][col].value === null)
2752
{
28-
checkRow(row,col,fullArray); //assemble and return possible values
29-
checkCol(row,col,fullArray); //assemble and return possible values
30-
temprow=row+1;
31-
tempcol=col+1;
32-
boxDeletePossibles(fullArray[row][col].possibles, checkBlock(temprow, tempcol, fullArray)); //assemble and return possible values
33-
}
34-
}
35-
}
3653

37-
insertSingletonValues(fullArray);
38-
//logSingletonValues(fullArray);
39-
};
54+
checkRow(row,col,fullArray); //assemble and return possible values
55+
checkCol(row,col,fullArray); //assemble and return possible values
56+
temprow=row+1;
57+
tempcol=col+1;
58+
boxDeletePossibles(fullArray[row][col].possibles, checkBlock(temprow, tempcol, fullArray)); //assemble and return possible values
59+
}
60+
}
61+
}
62+
//insertSingletonValues(fullArray);
63+
logSingletonValues(fullArray);
64+
//console.log(fullArray[3][1] )
65+
};
4066

4167
function logSingletonValues(fullArray){
4268
//iterate through big array
@@ -49,8 +75,8 @@ function logSingletonValues(fullArray){
4975
{
5076
if (fullArray[row][col].possibles.length === 1)
5177
{
52-
console.log(fullArray[row][col].possibles + " is possibles. xxxxxx" +
53-
fullArray[row][col].x + " zzzzz " + fullArray[row][col].y );
78+
console.log('possibles: ',fullArray[row][col].possibles,' x: ',fullArray[row][col].x,
79+
'y: ',fullArray[row][col].y);
5480
}
5581
}
5682
}
@@ -62,60 +88,82 @@ function insertSingletonValues(fullArray){
6288
var row, col;
6389
var lengthOne=0;
6490

65-
for (row=0; row<9; row++)
66-
{
67-
for (col=0; col<9; col++)
68-
{
69-
if (fullArray[row][col].possibles.length === 1)
70-
{
91+
for (row=0; row<9; row++) {
92+
for (col=0; col<9; col++) {
93+
if (fullArray[row][col].possibles.length === 1) {
7194
fullArray[row][col].value = fullArray[row][col].possibles[0];
7295
lengthOne = lengthOne +1;
96+
7397
}
7498
}
7599
}
76100
};
77101

78102

103+
function buildPrinterString(fullArray) {
104+
105+
106+
}
107+
108+
//findOptions2(fullArray);
109+
110+
// if (lengthOne=0){
111+
112+
// console.log("the fullArray is " + fullArray);
113+
114+
115+
116+
// }
117+
// else
118+
// {
119+
// cycleCount =cycleCount+1;
120+
// if (cycleCount < 100)
121+
// {
122+
// findOptions(fullArray);
123+
// console.log(" we are call findOptions ");
124+
// }
125+
// }
126+
127+
128+
79129

80130
function checkRow (row,col, fullArray){
81-
for (i = 0; i < 9; i++){ // iterate across columns
131+
for (i = 0; i < 9; i++) { // iterate across columns
82132
//console.log(fullArray[row][col] + row + " " + col + "xxxxx");
83-
if ( (fullArray[row][i].value !== null) && (fullArray[row][i] !== fullArray[row][col])
84-
)
85-
// if you find a null
86-
var toCheck = fullArray[row][i].value;
87-
{ //console.log("i is " + i);
88-
var possiblesList = fullArray[row][col].possibles;
89-
deletePossibles(toCheck, possiblesList);
133+
if ((fullArray[row][i].value !== null) && (fullArray[row][i] !== fullArray[row][col])) {
134+
// if you find a null
135+
var toCheck = fullArray[row][i].value;
136+
//console.log("i is " + i);
137+
var possiblesList = fullArray[row][col].possibles;
138+
deletePossibles(toCheck, possiblesList);
90139
}
91140
}
92141
};
93142

94143
function checkCol (row,col, fullArray){
95-
for (i = 0; i < 9; i++){ // iterate across rows
144+
for (i = 0; i < 9; i++) { // iterate across rows
96145
//console.log(fullArray[row][col] + row + " " + col + "xxxxx");
97-
if ( (fullArray[i][col].value !== null) && (fullArray[i][col] !== fullArray[row][col])
98-
)
146+
if ((fullArray[i][col].value !== null) && (fullArray[i][col] !== fullArray[row][col])) {
99147
// if you find a null
100-
var toCheck = fullArray[i][col].value;
101-
{
102-
var possiblesList = fullArray[row][col].possibles;
103-
deletePossibles(toCheck, possiblesList);
148+
var toCheck = fullArray[i][col].value;
149+
var possiblesList = fullArray[row][col].possibles;
150+
deletePossibles(toCheck, possiblesList);
104151
}
105152
}
106153
};
107154

108155
//iterate through possibles array and delete the toCheck element from possibles array
109156
function deletePossibles(toCheck, possiblesList){
157+
if (possiblesList.indexOf(toCheck) >= 0) {
110158
for (var i = 0; i < possiblesList.length; i++) {
111-
if (possiblesList[i] === toCheck)
112-
{possiblesList.splice(i, 1);
113-
//console.log("fullArray.possibles is " + possiblesList );
114-
return;
115-
};
116-
};
159+
if (possiblesList[i] === toCheck) {
160+
possiblesList.splice(i, 1);
161+
};
162+
};
163+
};
117164
};
118165

166+
119167
function boxDeletePossibles(possiblesList, callback){
120168
var array = callback;
121169
array.forEach(function(value, index){

0 commit comments

Comments
 (0)