@@ -2,25 +2,22 @@ var databuilder = require('./arraybuilder.js')
2
2
var printer = require ( './boardprinter.js' )
3
3
var checkBlock = require ( './checkBlock.js' ) ;
4
4
var printer = require ( './boardprinter.js' ) ;
5
- //var boardString = process.argv[2];
6
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 " ;
7
6
var boardArray = boardString . split ( '' ) ;
8
7
var cycleCount = 0 ;
9
8
10
9
console . log ( 'BEFORE: ' ) ;
11
- printer ( boardArray ) ;
10
+ // printer(boardArray);
12
11
13
- databuilder ( boardArray , findOptions ) ;
14
12
15
13
console . log ( 'AFTER: ' ) ;
16
- printer ( boardArray ) ;
14
+ // printer(boardArray);
17
15
18
16
databuilder ( boardArray , findOptions ) ;
19
17
20
18
function findOptions ( fullArray ) {
21
19
var row , col ;
22
- for ( row = 0 ; row < 9 ; row ++ )
23
- {
20
+ for ( row = 0 ; row < 9 ; row ++ ) {
24
21
for ( col = 0 ; col < 9 ; col ++ ) {
25
22
//console.log('row: ',row,'col: ',col);
26
23
//console.log("------------------");
@@ -42,14 +39,11 @@ function findOptions(fullArray){
42
39
43
40
function findOptions ( fullArray ) {
44
41
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("------------------");
49
44
// console.log("row is " + row + " and col is " + col + " value is "
50
45
// + 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 ) {
53
47
54
48
checkRow ( row , col , fullArray ) ; //assemble and return possible values
55
49
checkCol ( row , col , fullArray ) ; //assemble and return possible values
@@ -59,31 +53,30 @@ function findOptions(fullArray){
59
53
}
60
54
}
61
55
}
62
- // insertSingletonValues(fullArray);
63
- logSingletonValues ( fullArray ) ;
56
+ insertSingletonValues ( fullArray ) ;
57
+ // logSingletonValues(fullArray);
64
58
//console.log(fullArray[3][1] )
65
59
} ;
66
60
67
- function logSingletonValues ( fullArray ) {
61
+ function logSingletonValues ( fullArray ) {
68
62
//iterate through big array
69
63
var row , col ;
70
64
var lengthOne = 0 ;
71
65
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);
80
71
}
81
72
}
82
73
}
83
74
}
84
75
85
76
86
77
function insertSingletonValues ( fullArray ) {
78
+ buildPrinterString ( fullArray ) ;
79
+
87
80
//iterate through big array
88
81
var row , col ;
89
82
var lengthOne = 0 ;
@@ -93,47 +86,31 @@ function insertSingletonValues(fullArray){
93
86
if ( fullArray [ row ] [ col ] . possibles . length === 1 ) {
94
87
fullArray [ row ] [ col ] . value = fullArray [ row ] [ col ] . possibles [ 0 ] ;
95
88
lengthOne = lengthOne + 1 ;
96
-
97
89
}
98
90
}
99
91
}
100
92
} ;
101
93
102
94
103
95
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
+ } ;
129
108
130
109
function checkRow ( row , col , fullArray ) {
131
110
for ( i = 0 ; i < 9 ; i ++ ) { // iterate across columns
132
- //console.log(fullArray[row][col] + row + " " + col + "xxxxx");
133
111
if ( ( fullArray [ row ] [ i ] . value !== null ) && ( fullArray [ row ] [ i ] !== fullArray [ row ] [ col ] ) ) {
134
112
// if you find a null
135
113
var toCheck = fullArray [ row ] [ i ] . value ;
136
- //console.log("i is " + i);
137
114
var possiblesList = fullArray [ row ] [ col ] . possibles ;
138
115
deletePossibles ( toCheck , possiblesList ) ;
139
116
}
@@ -142,7 +119,6 @@ function checkRow (row,col, fullArray){
142
119
143
120
function checkCol ( row , col , fullArray ) {
144
121
for ( i = 0 ; i < 9 ; i ++ ) { // iterate across rows
145
- //console.log(fullArray[row][col] + row + " " + col + "xxxxx");
146
122
if ( ( fullArray [ i ] [ col ] . value !== null ) && ( fullArray [ i ] [ col ] !== fullArray [ row ] [ col ] ) ) {
147
123
// if you find a null
148
124
var toCheck = fullArray [ i ] [ col ] . value ;
@@ -169,5 +145,5 @@ function boxDeletePossibles(possiblesList, callback){
169
145
array . forEach ( function ( value , index ) {
170
146
deletePossibles ( value , possiblesList ) ;
171
147
} )
172
- }
148
+ } ;
173
149
0 commit comments