用python生成奇门遁甲的360天的每个时辰及落宫

输出结果见:https://tieba.baidu.com/p/5979125650

规律:
节气上元首局为所在宫位
同宫节气依次+1(阴遁-1)
每元首局为上个元的结尾再+1(阴遁-1)

用python生成奇门遁甲的360天的每个时辰及落宫_第1张图片

import sys

JieQi=["冬至","小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种",
       "夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪"];
SanYuan=["上元","中元","下元"];
JiuGong=[1,8,3,4,9,2,7,6];#每三个节气在一个宫内,此为顺时针旋转后天八卦的九宫数


gan1 = ["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"];
zhi1 = ["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"];

'''
阳遁:
冬至、惊蛰一七四,小寒二八五,
大寒、春分三九六,雨水九六三,
清明、立夏四一七,立春八五二,
谷雨、小满五二八,芒种六三九。
阴遁:
夏至、白露九三六,小暑八二五,
大暑、秋分七一四,立秋二五八,
寒露、立冬六九三,处暑一四七,
霜降、小雪五八二,大雪四七一。
'''

'''
甲子顺于总数,局数始于宫(节气),遁旋通元(三元)而得

局首为戊,遁飞得落宫(值使),找旬首(值符)

'''

#24节气*3元(1元5天)*5天*12时辰=360天的时辰数
#
#5天*12时辰=60时辰,一元60甲子
#60时辰%9宫=6,@一元衔接跳6


YinYangDun=1;#1阳遁,-1阴遁
sum=0;
sum1=0;
JuShu=0;#元,首局第几局
JuShu2=0;

print("所有0代表9");
#一年有二十四节气【a】
for a in range(24):
        
    if a<12 :                                               #阴阳遁【YinYangDun】
        YinYangDun=1;#阳遁
    else :
        YinYangDun=-1;#阴遁

    print("\n\n========"+JieQi[a]);                         #节气【a】
    #首局=【查表得宫】+余数(第一节气、第二节气、第三节气)
    ShouJu= (JiuGong[a//3]+ (a%3)*YinYangDun )%9 ;
    print("节气上元首局:"+ str(ShouJu));                       #节气首局【ShouJu】:冬至1,小寒2,大寒3

    #一个节气有三元【b】
    for b in range(3):
        print("\n----"+SanYuan[b]);                         #三元【b】显示,上中下
        JuShu= (ShouJu + sum1)%9;#节气的局,节气内三元的局
        print("第"+ str(JuShu) +"局");#一元之内                 #三元首局【JuShu】


        #----六十甲子----
        #一元有五天【c】
        JuShu2=JuShu;                                  #以旬首局数始【JuShu2】,局内落宫
        for c in range(5):#[0,4]

            #每天有十二时辰
            #print("第"+str(c)+"天开始");
            for d in range(12):
                #e1=((c-1)*12+(d-1))%10;#天干序号-1(数组从0开始)
                #e2=((c-1)*12+(d-1))%12;#地支序号-1
                e1=(sum%10);                            #其实干支是顺着局数一直下来的
                e2=(sum%12);

                if e1==0 : print("--"+str((c*12+(d+1))//10 +1)+"旬开始--");       #旬首(10个一次)

                print(gan1[e1]+zhi1[e2]+ ",落宫:"+ str((JuShu2)%9));        #显示时辰,"精确到当前时辰"

                JuShu2+=YinYangDun*1;
                sum1+=YinYangDun*1;
                sum+=1;                                                #总数

print(sum);

你可能感兴趣的:(Python,R,openXX,基础小程序,小技巧,出错异常)