Skip to content

Commit cf9d4a3

Browse files
committed
system outputs sum of all possibles arrays for each board
1 parent 505c94b commit cf9d4a3

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

sudoku.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ var printer = require('./boardprinter.js')
1414
var checkBlock = require('./checkBlock.js');
1515
var printer = require('./boardprinter.js');
1616

17+
1718
//NOT YET SOLVED
1819
var boardString = " 2 1 8 1 8 6 7 2 1 8 1 9 7 2 3 6 4 2 1 6 5 3 1 9 5 9 4 ";
1920

2021
//SOLVABLE
2122
//var boardString = "7 4 2 9 416 6 11 7 8 8 74132 9 9 8 56 2 413 8 2 8 6";
2223
//var boardString = " 8 3 42 6 9 332 4 9 75 9 6 6 185 7 8 4 93 3 4 515 7 2 26 9 1 "
2324

24-
25+
var unsolvedArraySize; // sums length of all possibles arrays
2526
var boardArray = boardString.split('');
2627
var masterCycleCount = 0;
2728
var masterCycleCountLimit = 5000;
@@ -36,12 +37,12 @@ databuilder(boardArray, findOptions);
3637
//set iteration control
3738

3839

39-
40-
4140
function findOptions(fullArray){
4241
var row, col;
4342
var solvedSquares = 0;
4443
masterCycleCount = masterCycleCount + 1;
44+
45+
4546
if (masterCycleCount >= masterCycleCountLimit){
4647
console.log('Master Cycle Limit Exceeded');
4748

@@ -92,7 +93,7 @@ function insertSingletonValue(fullArray){
9293
fullArray[row][col].value = fullArray[row][col].possibles[0]; //assign the value!
9394

9495

95-
console.log('Singleton assigned at: ' + (col + 1) + ', ' + (9-row));
96+
console.log('Singleton assigned at col: ' + (col + 1) + ', row:' + (9-row));
9697
console.log('Block is: ' + fullArray[row][col].block);
9798
buildPrinterString(fullArray);
9899

@@ -142,6 +143,8 @@ function insertDupleValues(fullArray){
142143
function buildPrinterString(fullArray){
143144
var printableArray = [];
144145
var set;
146+
var unsolvedArraySize = 0; // reset sum of length of all possibles arrays
147+
145148
for (row=0; row<9; row++) {
146149
for (col=0; col<9; col++) {
147150
if (fullArray[row][col].value === null){
@@ -161,6 +164,7 @@ function buildPrinterString(fullArray){
161164

162165
}
163166
//console.log ("set becomes: " + set);
167+
unsolvedArraySize = unsolvedArraySize + set;
164168
var space=set;
165169
printableArray.push(space);
166170
}
@@ -172,6 +176,8 @@ function buildPrinterString(fullArray){
172176
} //close for
173177
} //close for
174178
printer(printableArray);
179+
console.log("Total length of all posssibles arrays is: " + (-1 * unsolvedArraySize));
180+
175181
};// close final
176182

177183
// PREVIOUS VERSION OF BUILD PRINTER STRING - DELETE
@@ -217,18 +223,14 @@ function checkCol (row,col, fullArray){
217223
//iterate through possibles array and delete the toCheck element from possibles array
218224
function deletePossibles(toCheck, possiblesList){
219225

220-
221226
if (possiblesList.indexOf(toCheck) > -1) {
222227
for (var i = 0; i < possiblesList.length; i++) {
223228
if (possiblesList[i] === toCheck) {
224229
if (possiblesList.length < 2) {
225230
console.log('ERROR CHECKER WORKED ___________________ ON SQUARE ');
226231

227-
228232
//console.log(arrayDepot[0][0]['possibles']);
229233

230-
231-
232234
/// Temp comment out - go to first in
233235
//findOptions(arrayDepot.shift());
234236

@@ -248,6 +250,16 @@ function deletePossibles(toCheck, possiblesList){
248250
};
249251
};
250252

253+
// // IN DEVELOPMENT - A FUNCTION TO PICK SMALLEST POSSIBLE ARRAY COUNT ARRAY?
254+
// function selectBestFromArrayDepot(arrayDepot){
255+
// for (i=0; i<arrayDepot.length; i++)
256+
// for (row=0; row<9; row++) {
257+
// for (col=0; col<9; col++) {
258+
// if (fullArray[row][col].value <0 {
259+
// sumPossibles=sumPossibles + (fullArray[row][col].possibles;
260+
261+
// };
262+
251263

252264
function boxDeletePossibles(possiblesList, callback){
253265
var array = callback;

0 commit comments

Comments
 (0)