Skip to content

Commit 68e9667

Browse files
committed
adding buildPrinterString function
1 parent 254223c commit 68e9667

File tree

1 file changed

+29
-53
lines changed

1 file changed

+29
-53
lines changed

sudoku.js

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,22 @@ var databuilder = require('./arraybuilder.js')
22
var printer = require('./boardprinter.js')
33
var checkBlock = require('./checkBlock.js');
44
var printer = require('./boardprinter.js');
5-
//var boardString = process.argv[2];
65
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 ";
76
var boardArray = boardString.split('');
87
var cycleCount=0;
98

109
console.log('BEFORE: ');
11-
printer(boardArray);
10+
//printer(boardArray);
1211

13-
databuilder(boardArray, findOptions);
1412

1513
console.log('AFTER: ');
16-
printer(boardArray);
14+
//printer(boardArray);
1715

1816
databuilder(boardArray, findOptions);
1917

2018
function findOptions(fullArray){
2119
var row, col;
22-
for (row=0; row<9; row++)
23-
{
20+
for (row=0; row<9; row++) {
2421
for (col=0; col<9; col++) {
2522
//console.log('row: ',row,'col: ',col);
2623
//console.log("------------------");
@@ -42,14 +39,11 @@ function findOptions(fullArray){
4239

4340
function findOptions(fullArray){
4441
var row, col;
45-
for (row=0; row<9; row++)
46-
{
47-
for (col=0; col<9; col++)
48-
{ //console.log("------------------");
42+
for (row=0; row<9; row++) {
43+
for (col=0; col<9; col++) { //console.log("------------------");
4944
// console.log("row is " + row + " and col is " + col + " value is "
5045
// + fullArray[row][col].value + " and block is " + fullArray[row][col].block);
51-
if (fullArray[row][col].value === null)
52-
{
46+
if (fullArray[row][col].value === null) {
5347

5448
checkRow(row,col,fullArray); //assemble and return possible values
5549
checkCol(row,col,fullArray); //assemble and return possible values
@@ -59,31 +53,30 @@ function findOptions(fullArray){
5953
}
6054
}
6155
}
62-
//insertSingletonValues(fullArray);
63-
logSingletonValues(fullArray);
56+
insertSingletonValues(fullArray);
57+
//logSingletonValues(fullArray);
6458
//console.log(fullArray[3][1] )
6559
};
6660

67-
function logSingletonValues(fullArray){
61+
function logSingletonValues(fullArray) {
6862
//iterate through big array
6963
var row, col;
7064
var lengthOne=0;
7165

72-
for (row=0; row<9; row++)
73-
{
74-
for (col=0; col<9; col++)
75-
{
76-
if (fullArray[row][col].possibles.length === 1)
77-
{
78-
console.log('possibles: ',fullArray[row][col].possibles,' x: ',fullArray[row][col].x,
79-
'y: ',fullArray[row][col].y);
66+
for (row=0; row<9; row++) {
67+
for (col=0; col<9; col++) {
68+
if (fullArray[row][col].possibles.length === 1) {
69+
//console.log('possibles: ',fullArray[row][col].possibles,' x: ',fullArray[row][col].x,
70+
//'y: ',fullArray[row][col].y);
8071
}
8172
}
8273
}
8374
}
8475

8576

8677
function insertSingletonValues(fullArray){
78+
buildPrinterString(fullArray);
79+
8780
//iterate through big array
8881
var row, col;
8982
var lengthOne=0;
@@ -93,47 +86,31 @@ function insertSingletonValues(fullArray){
9386
if (fullArray[row][col].possibles.length === 1) {
9487
fullArray[row][col].value = fullArray[row][col].possibles[0];
9588
lengthOne = lengthOne +1;
96-
9789
}
9890
}
9991
}
10092
};
10193

10294

10395
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-
96+
var printableArray = [];
97+
fullArray.forEach(function(record) {
98+
for (var i = 0; i <= 8;i++) {
99+
if (record[i]['value'] === null) {
100+
printableArray.push(' ');
101+
} else {
102+
printableArray.push(record[i]['value']);
103+
}
104+
}
105+
});
106+
printer(printableArray);
107+
};
129108

130109
function checkRow (row,col, fullArray){
131110
for (i = 0; i < 9; i++) { // iterate across columns
132-
//console.log(fullArray[row][col] + row + " " + col + "xxxxx");
133111
if ((fullArray[row][i].value !== null) && (fullArray[row][i] !== fullArray[row][col])) {
134112
// if you find a null
135113
var toCheck = fullArray[row][i].value;
136-
//console.log("i is " + i);
137114
var possiblesList = fullArray[row][col].possibles;
138115
deletePossibles(toCheck, possiblesList);
139116
}
@@ -142,7 +119,6 @@ function checkRow (row,col, fullArray){
142119

143120
function checkCol (row,col, fullArray){
144121
for (i = 0; i < 9; i++) { // iterate across rows
145-
//console.log(fullArray[row][col] + row + " " + col + "xxxxx");
146122
if ((fullArray[i][col].value !== null) && (fullArray[i][col] !== fullArray[row][col])) {
147123
// if you find a null
148124
var toCheck = fullArray[i][col].value;
@@ -169,5 +145,5 @@ function boxDeletePossibles(possiblesList, callback){
169145
array.forEach(function(value, index){
170146
deletePossibles(value, possiblesList);
171147
})
172-
}
148+
};
173149

0 commit comments

Comments
 (0)