Skip to content

Commit 4c3e1bc

Browse files
committed
merge
2 parents 0fd4b92 + 1638c20 commit 4c3e1bc

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

sudoku.js

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ var checkBlock = require('./checkBlock.js');
88
var printer = require('./boardprinter.js');
99
var boardString = "8 2 5 97 4 25 1 9 2 7 96 3 1 52 6 1 8 4 73 7 65 3 8 9"
1010
var boardArray = boardString.split('');
11+
1112
var cycleCount = 0;
1213
var cycleCountLimit = 6;
1314
var masterCycleCount = 0;
1415
var masterCycleCountLimit = 15;
16+
1517
var arrayDepot = [];
1618
var arrayDepotIndex = 0;
19+
1720
var iterateControl = [' '];
1821

1922
var doneArray; //to pass from findOptions to logSingleton
@@ -33,10 +36,9 @@ function findOptions(fullArray){
3336

3437
return }
3538
for (row=0; row<9; row++) {
36-
for (col=0; col<9; col++) {
37-
39+
for (col=0; col<9; col++) {
3840
if (fullArray[row][col].value === null) {
39-
solvedSquares = 1;
41+
solvedSquares = 1;
4042
checkRow(row,col,fullArray); //assemble and return possible values
4143
checkCol(row,col,fullArray); //assemble and return possible values
4244
temprow = row+1;
@@ -54,10 +56,54 @@ function findOptions(fullArray){
5456
console.log('cycle count: ' + cycleCount);
5557
console.log('array depot index: ' + arrayDepotIndex);
5658
console.log('array depot length ' + arrayDepot.length)
57-
insertSingletonValues(fullArray);
58-
59+
//insertSingletonValues(fullArray);
60+
insertSingletonValue(fullArray); //insert ONLY ONE value
61+
5962
};
6063

64+
//Inserts only one singleton value prior to recalculation
65+
function insertSingletonValue(fullArray){
66+
var possibleLengths = 0;
67+
var row, col;
68+
cycleCount = cycleCount +1;
69+
70+
if (cycleCount === cycleCountLimit) {
71+
cycleCount = 0;
72+
console.log('calling findOptions from arrayDepot')
73+
74+
arrayDepotIndex = arrayDepotIndex + 1;
75+
var arrayToPass = arrayDepotIndex - 1;
76+
buildPrinterString(arrayDepot[arrayToPass]);
77+
findOptions(arrayDepot[arrayToPass]);
78+
79+
};
80+
81+
for (row=0; row<9; row++) {
82+
for (col=0; col<9; col++) {
83+
if (fullArray[row][col].possibles.length === 1 && fullArray[row][col].value === null) {
84+
possibleLengths = 1;
85+
fullArray[row][col].value = fullArray[row][col].possibles[0];
86+
console.log('Singleton assigned at: ' + (col + 1) + ', ' + (9-row));
87+
console.log('Block is: ' + fullArray[row][col].block);
88+
console.log('Possibles Array for location is ' + fullArray[row][col].possibles[0]);
89+
buildPrinterString(fullArray);
90+
91+
92+
//after finding ONE singleton, display something
93+
94+
findOptions(fullArray);
95+
96+
97+
}
98+
}
99+
}
100+
if (possibleLengths === 0) {
101+
console.log('NO NEW POSSIBLES ARRAYS WITH A LENGTH OF 1');
102+
buildPrinterString(fullArray);
103+
insertDupleValues(fullArray);
104+
}
105+
};
106+
//inserts all singleton values prior to recalculation?
61107
function insertSingletonValues(fullArray){
62108
var possibleLengths = 0;
63109
var row, col;
@@ -78,6 +124,8 @@ function insertSingletonValues(fullArray){
78124
possibleLengths = 1;
79125
fullArray[row][col].value = fullArray[row][col].possibles[0];
80126
console.log('Singleton assigned at: ' + (col + 1) + ', ' + (9-row));
127+
console.log('Block is: ' + fullArray[row][col].block);
128+
console.log('Possibles Array for location is ' + fullArray[row][col].possibles[0]);
81129
buildPrinterString(fullArray);
82130
}
83131
}
@@ -90,6 +138,10 @@ function insertSingletonValues(fullArray){
90138
findOptions(fullArray);
91139
};
92140

141+
142+
143+
144+
93145
function insertDupleValues(fullArray){
94146
for (row=0; row<9; row++) {
95147
for (col=0; col<9; col++) {

0 commit comments

Comments
 (0)