-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudsol.js
193 lines (190 loc) · 6.1 KB
/
sudsol.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Generated by CoffeeScript 1.6.1
(function() {
var GrilleView, grille_view;
GrilleView = Backbone.View.extend({
initialize: function() {
return this.render();
},
render: function() {
var i, j, _i, _j, _results;
_results = [];
for (i = _i = 1; _i <= 9; i = ++_i) {
for (j = _j = 1; _j <= 9; j = ++_j) {
this.renderBox(i, j);
}
_results.push(this.$el.append("<br/>"));
}
return _results;
},
renderBox: function(i, j) {
var template;
template = _.template($("#box-template").html(), {
i: i,
j: j
});
return this.$el.append(template);
},
events: {
"change input[type=text]": "doWork"
},
doWork: function(event) {
var POSITION_EXTRACTOR, extract_result, knownTarget, knownValue, position_i, position_j;
knownValue = event.target.value;
knownTarget = event.target.id;
POSITION_EXTRACTOR = /^box-(\d)-(\d)-val$/;
extract_result = POSITION_EXTRACTOR.exec(knownTarget);
position_i = extract_result[1];
position_j = extract_result[2];
$("#box-" + position_i + "-" + position_j + "-possib").html("_");
$("#box-" + position_i + "-" + position_j + "-possib").removeClass("green");
return this.rmPossib(knownValue, position_i, position_j);
},
rmPossib: function(value, i, j) {
var k, l, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _results, _results1, _results2, _results3, _results4, _results5, _results6, _results7, _results8, _s;
for (k = _i = 1; _i <= 9; k = ++_i) {
this.rmBoxPossib(value, i, k);
}
for (k = _j = 1; _j <= 9; k = ++_j) {
this.rmBoxPossib(value, k, j);
}
if (i < 4) {
if (j < 4) {
_results = [];
for (k = _k = 1; _k <= 3; k = ++_k) {
_results.push((function() {
var _l, _results1;
_results1 = [];
for (l = _l = 1; _l <= 3; l = ++_l) {
_results1.push(this.rmBoxPossib(value, k, l));
}
return _results1;
}).call(this));
}
return _results;
} else if (j > 6) {
_results1 = [];
for (k = _l = 1; _l <= 3; k = ++_l) {
_results1.push((function() {
var _m, _results2;
_results2 = [];
for (l = _m = 7; _m <= 9; l = ++_m) {
_results2.push(this.rmBoxPossib(value, k, l));
}
return _results2;
}).call(this));
}
return _results1;
} else {
_results2 = [];
for (k = _m = 1; _m <= 3; k = ++_m) {
_results2.push((function() {
var _n, _results3;
_results3 = [];
for (l = _n = 4; _n <= 6; l = ++_n) {
_results3.push(this.rmBoxPossib(value, k, l));
}
return _results3;
}).call(this));
}
return _results2;
}
} else if (i > 6) {
if (j < 4) {
_results3 = [];
for (k = _n = 7; _n <= 9; k = ++_n) {
_results3.push((function() {
var _o, _results4;
_results4 = [];
for (l = _o = 1; _o <= 3; l = ++_o) {
_results4.push(this.rmBoxPossib(value, k, l));
}
return _results4;
}).call(this));
}
return _results3;
} else if (j > 6) {
_results4 = [];
for (k = _o = 7; _o <= 9; k = ++_o) {
_results4.push((function() {
var _p, _results5;
_results5 = [];
for (l = _p = 7; _p <= 9; l = ++_p) {
_results5.push(this.rmBoxPossib(value, k, l));
}
return _results5;
}).call(this));
}
return _results4;
} else {
_results5 = [];
for (k = _p = 7; _p <= 9; k = ++_p) {
_results5.push((function() {
var _q, _results6;
_results6 = [];
for (l = _q = 4; _q <= 6; l = ++_q) {
_results6.push(this.rmBoxPossib(value, k, l));
}
return _results6;
}).call(this));
}
return _results5;
}
} else {
if (j < 4) {
_results6 = [];
for (k = _q = 4; _q <= 6; k = ++_q) {
_results6.push((function() {
var _r, _results7;
_results7 = [];
for (l = _r = 1; _r <= 3; l = ++_r) {
_results7.push(this.rmBoxPossib(value, k, l));
}
return _results7;
}).call(this));
}
return _results6;
} else if (j > 6) {
_results7 = [];
for (k = _r = 4; _r <= 6; k = ++_r) {
_results7.push((function() {
var _results8, _s;
_results8 = [];
for (l = _s = 7; _s <= 9; l = ++_s) {
_results8.push(this.rmBoxPossib(value, k, l));
}
return _results8;
}).call(this));
}
return _results7;
} else {
_results8 = [];
for (k = _s = 4; _s <= 6; k = ++_s) {
_results8.push((function() {
var _results9, _t;
_results9 = [];
for (l = _t = 4; _t <= 6; l = ++_t) {
_results9.push(this.rmBoxPossib(value, k, l));
}
return _results9;
}).call(this));
}
return _results8;
}
}
},
rmBoxPossib: function(value, i, j) {
var SOLVED, newPossib;
SOLVED = /^\d$/;
newPossib = $("#box-" + i + "-" + j + "-possib").html();
newPossib = newPossib.replace("," + value, "");
newPossib = newPossib.replace("" + value + ",", "");
$("#box-" + i + "-" + j + "-possib").html(newPossib);
if (SOLVED.test(newPossib)) {
return $("#box-" + i + "-" + j + "-possib").addClass("green");
}
}
});
grille_view = new GrilleView({
el: $("#grille")
});
}).call(this);