@@ -5,37 +5,32 @@ var checkBlock = require('./checkBlock.js');
5
5
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 " ;
6
6
var boardArray = boardString . split ( '' ) ;
7
7
var cycleCount = 0 ;
8
+ var doneArray ; //to pass from findOptions to logSingleton
8
9
9
10
10
11
databuilder ( boardArray , findOptions ) ;
12
+ //set iteration control
11
13
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
+ } ;
30
29
31
- insertSingletonValues ( fullArray ) ;
32
- //logSingletonValues(fullArray);
33
- console . log ( fullArray [ 3 ] [ 1 ] )
34
30
35
31
36
- } ;
37
32
38
- function findOptions2 ( fullArray ) {
33
+ function findOptions ( fullArray ) {
39
34
var row , col ;
40
35
for ( row = 0 ; row < 9 ; row ++ )
41
36
{
@@ -53,20 +48,13 @@ function findOptions2(fullArray){
53
48
}
54
49
}
55
50
}
56
-
57
- //insertSingletonValues(fullArray);
51
+ insertSingletonValues ( fullArray ) ;
58
52
logSingletonValues ( fullArray ) ;
59
53
console . log ( fullArray [ 3 ] [ 1 ] )
60
-
61
-
54
+ doneArray = fullArray ;
62
55
} ;
63
56
64
-
65
-
66
-
67
-
68
-
69
-
57
+
70
58
function logSingletonValues ( fullArray ) {
71
59
//iterate through big array
72
60
var row , col ;
@@ -78,18 +66,19 @@ function logSingletonValues(fullArray){
78
66
{
79
67
if ( fullArray [ row ] [ col ] . possibles . length === 1 )
80
68
{
81
- console . log ( fullArray [ row ] [ col ] . possibles + " is possibles. xxxxxx" +
69
+ console . log ( fullArray [ row ] [ col ] . possibles + " is possibles. xxxxxx " +
82
70
fullArray [ row ] [ col ] . x + " zzzzz " + fullArray [ row ] [ col ] . y ) ;
83
71
}
84
72
}
85
73
}
86
74
}
87
75
88
-
89
76
function insertSingletonValues ( fullArray ) {
90
77
//iterate through big array
91
78
var row , col ;
92
79
var lengthOne = 0 ;
80
+ countCycle = countCycle + 1 ;
81
+ if ( countCycle > countCycleLimit ) { return } ;
93
82
94
83
for ( row = 0 ; row < 9 ; row ++ )
95
84
{
@@ -98,31 +87,10 @@ function insertSingletonValues(fullArray){
98
87
if ( fullArray [ row ] [ col ] . possibles . length === 1 )
99
88
{
100
89
fullArray [ row ] [ col ] . value = fullArray [ row ] [ col ] . possibles [ 0 ] ;
101
- lengthOne = lengthOne + 1 ;
102
-
90
+ lengthOne = lengthOne + 1 ;
103
91
}
104
92
}
105
-
106
93
}
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
-
126
94
} ;
127
95
128
96
0 commit comments