我正在構建使用下劃線模板的數獨板。我在計算數學表達式結構時遇到了一些麻煩。構建使用下劃線模板的數獨板
我的基礎結構是一個1d數組(大小爲81)。我相信解決這個問題的最好方法是用3x3的小立方體來構建它。
[1,2,3,4 ....] - > [1,2,3 [1,2,3 .... 4,5,6 4,5,6 7,8 ,9] 7,8,9]
但我無法弄清楚如何獲取第一個立方體的值,然後是下一個,然後是下一個。
應該類似
<%
//Defining each cube
for (var x = 0; x < 9; x++) {
%>
<div class="parentCube">
<%
//Defining each cell in cube
for (var y = 0; y < 9; y++) {
console.log('x: ' + x + ' y: ' + y);
%>
<div class="childCube">
<%=
//Heres where im having trouble, how do you look up the 1d array index using the outlying for loop
matrix.indexOf(??);
%>
</div>
<%
}
%>
</div>
<%
}
%>
//should follow this equation
0,0 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8
[0,0], [1,0], [2,0], [0,1], [1,1], [2,1], [0,2], [1,2], [2,2]
1,0 1,1 1,2 1,3 1,4 1,5 1,6 1,7 1,8
[3,0], [4,0], [5,0], [3,1], [4,1], [5,1], [3,2], [4,2], [5,2]
2,0 2,1 2,2 2,3 2,4 2,5 2,6 2,7 2,8
[6,0], [7,0], [8,0], [6,1], [7,1], [8,1], [6,2], [7,2], [8,2]
3,0 3,1 3,2 3,3 3,4 3,5 3,6 3,7 3,8
[0,3], [1,3], [2,3], [0,4], [1,4], [2,4], [0,5], [1,5], [2,5]
// Or this structure of X/Y's
X
0,1,2,0,1,2,0,1,2, 3,4,5,3,4,5,3,4,5, 6,7,8,6,7,8,6,7,8,
0,1,2,0,1,2,0,1,2, 3,4,5,3,4,5,3,4,5, 6,7,8,6,7,8,6,7,8,
0,1,2,0,1,2,0,1,2, 3,4,5,3,4,5,3,4,5, 6,7,8,6,7,8,6,7,8,
Y
0,0,0,1,1,1,2,2,2, 0,0,0,1,1,1,2,2,2, 0,0,0,1,1,1,2,2,2,
3,3,3,4,4,4,5,5,5, 3,3,3,4,4,4,5,5,5, 3,3,3,4,4,4,5,5,5,
6,6,6,7,7,7,8,8,8, 6,6,6,7,7,7,8,8,8, 6,6,6,7,7,7,8,8,8,
我已經解決了在x式中,(Y%3 +(X * 3))%9;我現在正在研究y,因爲它如何包裹,這有點困難。