八宫相逢数之计算

import numpy as np

x1 = [1,2,3,4,5,6,7,8,9];
x2 = [1,8,3,4,9,2,7,6];

star = [1,26,3,4,45,38,7,24];

yuandan=[0,1,2,3,-1,5,7,8,9]

pos1 = 0;
pos2 = x2.index(x1[pos1])

for i in range(0,72):
#九宫位置
pos3 = x1[(i+pos1)%9]
pos4 = x2[(i+pos2)%8]
# print (pos3,end=’,’)
# print (pos4)
if pos3==pos4:
yuandan[pos3-1] = i+1

for index in range(1,9):
pos1 = index
if pos1==4:
continue
pos2 = x2.index(index+1)
gong1 = [[0 for i in range(8)] for i in range(9)]
gong2 = [[0 for i in range(9)] for i in range(8)]

for i in range(0,72):
v = i % 72+1
gong1[(pos1+i)%9][int(i/9)] = v
gong2[(pos2+i)%8][int(i/8)] = v

for index in range(9):
if (index==4):
continue
v1 = gong1[index]
v2 = gong2[x2.index(index+1)]

temp = np.intersect1d(v1,v2)
print (temp,end=’,’)
print()

结果:

[1, 38, 3, 4, -1, 24, 7, 26, 45]
[36],[1],[38],[39],[59],[42],[61],[8],
[71],[36],[1],[2],[22],[5],[24],[43],
[70],[35],[72],[1],[21],[4],[23],[42],
[50],[15],[52],[53],[1],[56],[3],[22],
[67],[32],[69],[70],[18],[1],[20],[39],
[48],[13],[50],[51],[71],[54],[1],[20],
[29],[66],[31],[32],[52],[35],[54],[1]

发表评论

电子邮件地址不会被公开。 必填项已用*标注