,我想将对角线约束到一定的数值,即: blockquote A + D + H = B + E + I + M = ... = L + P + S = CONST_SUM
我想通过计算每个级别的跳数来展开列表并试图找出一些数学公式来获得正确的元素。到目前为止,我只有这样: $ $ p $ $ code矩阵([[1,2,3],[4,5,6, 7] [8,9,10,11,12],[13,14,15,16],[17,18,19])。 检查(M): - 矩阵(M),变平(M,L), check_sum(L,1)。
然而,数学方法在文章中似乎并不顺利。任何想法? / p>
编辑:
I无法计算出数学规则(每个对角线的跳数),也许还有另一种方法,我应该遵循,而不是平坦的方法... ...
解决方案C 。 。 D,E,F,G。 H,I,J,K,L 。 M,N,O,P 。 。 Q,R,S
然后一种对角线会有固定的 x (列),另一个固定的 y 条目(行)和第三个固定的 x - y )。如果你把它弄平,你必须以某种方式代表围绕着形状的空单元,并且在迭代时将它们加密,或者首先将它们从迭代中排除。您需要额外的内存支付更简单的公式。
The shape is like this:
A,B,C D,E,F,G H,I,J,K,L M,N,O,P Q,R,Sand I want to constraint the diagonals to a certain sum, i.e.:
A+D+H = B+E+I+M = ... = L+P+S = CONST_SUM
I thought of flattening the list and trying to work out some mathematical formulas to obtain the correct elements, by computing the hops at each level. So far, I have only this:
matrix([[1,2,3],[4,5,6,7][8,9,10,11,12],[13,14,15,16],[17,18,19]). check(M) :- matrix(M), flatten(M, L), check_sum(L, 1).However, the math approach doesn't seem to go well in the paper..Any ideas?
EDIT:
I couldn't work out the math rules (the hops for every diagonal), maybe there is another approach that I should follow, and not the flattening one...
解决方案One thing you can do is write the hexagon skewed like this:
A,B,C . . D,E,F,G . H,I,J,K,L . M,N,O,P . . Q,R,SThen one kind of diagonals will have fixed x entry ("columns"), another fixed y entry ("rows"), and a third fixed x−y difference ("descending diagonals"). If you flatten this, you have to somehow represent the empty cells surrounding the shape, and either dkip them while iterating or exclude them from the iteration in the first place. You pay for the simpler formula by extra memory requirements.
更多推荐
如何获得六角形的对角线?
发布评论