Skip to content

Latest commit

 

History

History
438 lines (353 loc) · 10.5 KB

234-562522-[趣味拓展]周易占卜算卦.sy.md

File metadata and controls

438 lines (353 loc) · 10.5 KB
show version enable_checker
step
1.0
true

持续集成(Continuous Integration)

回忆

  • 上次了解到函数是有一个个模块构成的
  • 一个模块一个功能
    • 高内聚
    • 低耦合
  • 我们可以做一个什么样的具体应用么?

图片描述

  • 比如周易占卜?🤔

占卜的起源

图片描述

  • 先写下卜辞

  • 龟甲、牛肩胛骨

  • 通常先在准备用来占卜的甲骨的背面

  • 挖出或钻出一些小坑

  • 占卜用火烧小坑

  • 正面即出现“卜”字形裂纹

  • 裂纹叫做“兆”

    • “兆头”、“预兆”

图片描述

卜辞

图片描述

  • 并把占卜的内容及结果刻录下来
    • 即是“卜辞”
  • 真实结果出现后
    • 验证贞不贞

周易

  • 系辞传
  • 大衍之数五十
    • 其用四十有九
  • 分而爲二以象两
  • 挂一以象三
  • 揲之以四以象四时
  • 归奇于扐以象闰
  • 五岁再闰
  • 故再扐而后挂

图片描述

  • 天数五,地数五,五位相得而各有合
  • 天数二十有五,地数三十,凡天地之数五十有五
  • 此所以成变化而行鬼神也

占什么

  • 首先要知道自己要问些什么

  • 能够发现问题其实就已经开始解决问题

  • 大衍之数五十

图片描述

  • 其用四十有九
  • 留一根象征大道本体不变

图片描述

象两

  • 分而爲二以象两

图片描述

  • 分出了阴阳两仪

图片描述

挂一以象三

  • 下图中从左到右分别代表天、地、人三才
  • 人生于地、长于地
  • 所以刚刚我们从代表地的一组中取出一根代表人

图片描述

  • 我们从右边一组中取出一根放于左手两指间
  • 此为挂一

图片描述

揲之以四以象四时

  • 将右边的蓍草
  • 四根一组开始数
  • 四象征春夏秋冬四季
  • 最后剩下四种可能
    • [1,2,3,4]
  • 将剩余的放于左手两指之间
  • 和刚才取出的一根一起放起来

图片描述

  • 揲之以四以象四时
  • 归奇于扐以象闰

图片描述

五岁再闰

  • 故再扐而后挂
  • 将左边一组也用类似方法处理

图片描述

得到结果

图片描述

  • 是5或者9
  • 把取出的排除之后
  • 再做一轮

第二轮

图片描述

第二轮结果

图片描述

  • 4或8
  • 把第二轮得到的排除之后
  • 开始第三轮

第三轮

图片描述

第三轮结果

图片描述

结果的可能性

图片描述

4种可能

  • 除以4得到
  • [9,8,7,6]四种可能

图片描述

  • 9 老阳
  • 8 少阴
  • 7 少阳
  • 6 老阴
  • 如此可以得到一爻
  • 一卦里有6爻

获得六爻

图片描述

  • 运行结果

图片描述

获得主卦和之卦

import random

def get_number(num):
    tian = random.randint(0,num)
    di = num - tian
    #print(tian, ",", di, ",", num)
    di = di - 1
    run_di = di % 4
    if run_di == 0:
        run_di = 4
    run_di = run_di + 1
    run_tian = (tian - 1) % 4
    if run_tian == 0:
        run_tian = 4
    run_tian = run_tian + 1
    #print(run_tian,",",run_di,",", run_tian + run_di)
    return num - run_tian - run_di

l_zhu = list()
l_zhi = list()

for i in range(6):
    round_1 = get_number(50 - 1)
    round_2 = get_number(round_1)
    round_3 = get_number(round_2)
    result = round_3 // 4
    if result == 6:
        l_zhu.append("0")
        l_zhi.append("1")
    elif result == 7:
        l_zhu.append("1")
        l_zhi.append("1")
    elif result == 8:
        l_zhu.append("0")
        l_zhi.append("0")
    else:
        l_zhu.append("1")
        l_zhi.append("0")

print(l_zhu,l_zhi)
  • 运行结果

图片描述

对应卦象

  • 卦象字典
d = {
    "000000": "地势坤",
    "000001": "地雷复",
    "000010": "地水师",
    "000011": "地泽临",
    "000100": "地山谦",
    "000101": "地火明夷",
    "000110": "地风升",
    "000111": "地天泰",
    "001000": "雷地豫",
    "001001": "震为雷",
    "001010": "雷水解",
    "001011": "雷泽归妹",
    "001100": "雷山小过",
    "001101": "雷火丰",
    "001110": "雷风恒",
    "001111": "雷天大壮",
    "010000": "水地比",
    "010001": "水雷屯",
    "010010": "坎为水",
    "010011": "水泽节",
    "010100": "水山蹇",
    "010101": "水火即济",
    "010110": "水风井",
    "010111": "水天需",
    "011000": "泽地萃",
    "011001": "泽雷随",
    "011010": "泽水困",
    "011011": "兑为泽",
    "011100": "泽山咸",
    "011101": "泽火革",
    "011110": "泽风大过",
    "011111": "泽天夬",
    "100000": "山地剥",
    "100001": "山雷颐",
    "100010": "山水蒙",
    "100011": "山泽损",
    "100100": "艮为山",
    "100101": "山火贲",
    "100110": "山风蛊",
    "100111": "山天大畜",
    "101000": "火地晋",
    "101001": "火雷噬嗑",
    "101010": "火水未济",
    "101011": "火泽睽",
    "101100": "火山旅",
    "101101": "离为火",
    "101110": "火风鼎",
    "101111": "火天大有",
    "110000": "风地观",
    "110001": "风雷益",
    "110010": "风水涣",
    "110011": "风泽中孚",
    "110100": "风山渐",
    "110101": "风火家人",
    "110110": "巽为风",
    "110111": "风天小畜",
    "111000": "天地否",
    "111001": "天雷无妄",
    "111010": "天水讼",
    "111011": "天泽履",
    "111100": "天山遁",
    "111101": "天火同人",
    "111110": "天风姤",
    "111111": "天行健(乾)"
}
  • 将两部分链接起来
  • 封装成一个函数

链接

import random
def zhan():
    d = {
        "000000": "地势坤",
        "000001": "地雷复",
        "000010": "地水师",
        "000011": "地泽临",
        "000100": "地山谦",
        "000101": "地火明夷",
        "000110": "地风升",
        "000111": "地天泰",
        "001000": "雷地豫",
        "001001": "震为雷",
        "001010": "雷水解",
        "001011": "雷泽归妹",
        "001100": "雷山小过",
        "001101": "雷火丰",
        "001110": "雷风恒",
        "001111": "雷天大壮",
        "010000": "水地比",
        "010001": "水雷屯",
        "010010": "坎为水",
        "010011": "水泽节",
        "010100": "水山蹇",
        "010101": "水火即济",
        "010110": "水风井",
        "010111": "水天需",
        "011000": "泽地萃",
        "011001": "泽雷随",
        "011010": "泽水困",
        "011011": "兑为泽",
        "011100": "泽山咸",
        "011101": "泽火革",
        "011110": "泽风大过",
        "011111": "泽天夬",
        "100000": "山地剥",
        "100001": "山雷颐",
        "100010": "山水蒙",
        "100011": "山泽损",
        "100100": "艮为山",
        "100101": "山火贲",
        "100110": "山风蛊",
        "100111": "山天大畜",
        "101000": "火地晋",
        "101001": "火雷噬嗑",
        "101010": "火水未济",
        "101011": "火泽睽",
        "101100": "火山旅",
        "101101": "离为火",
        "101110": "火风鼎",
        "101111": "火天大有",
        "110000": "风地观",
        "110001": "风雷益",
        "110010": "风水涣",
        "110011": "风泽中孚",
        "110100": "风山渐",
        "110101": "风火家人",
        "110110": "巽为风",
        "110111": "风天小畜",
        "111000": "天地否",
        "111001": "天雷无妄",
        "111010": "天水讼",
        "111011": "天泽履",
        "111100": "天山遁",
        "111101": "天火同人",
        "111110": "天风姤",
        "111111": "天行健(乾)"
    }
    def get_number(num):
        tian = random.randint(0,num)
        di = num - tian
        #print(tian, ",", di, ",", num)
        di = di - 1
        run_di = di % 4
        if run_di == 0:
            run_di = 4
        run_di = run_di + 1
        run_tian = (tian - 1) % 4
        if run_tian == 0:
            run_tian = 4
        run_tian = run_tian + 1
        #print(run_tian,",",run_di,",", run_tian + run_di)
        return num - run_tian - run_di

    def zhanpu():
	    s_zhu = str()
	    s_zhi = str()
	
	    for i in range(6):
	        round_1 = get_number(50 - 1)
	        round_2 = get_number(round_1)
	        round_3 = get_number(round_2)
	        result = round_3 // 4
	        if result == 6:
	            s_zhu += "0"
	            s_zhi += "1"
	        elif result == 7:
	            s_zhu += "1"
	            s_zhi += "1"
	        elif result == 8:
	            s_zhu += "0"
	            s_zhi += "0"
	        else:
	            s_zhu += "1"
	            s_zhi += "0"
	
	    print(d[s_zhu])
	    print("之")
	    print(d[s_zhi])

	zhanpu()

zhan()

总结

  • 周易博大精深
  • 里面蕴含着很多古老的道理
  • 真的弄懂不容易
  • 善易者不卜
  • 自己去实践判断才有真实的收获
  • 比如模块化的道理
  • 一个模块一个功能
    • 高内聚
    • 低耦合
  • 模块化就都是优点么?
  • 就没有什么模块化导致的问题么?🤔
  • 我们下次再说👋